Skip to content

Commit 123809c

Browse files
[qmlboxmodel] archive wip
1 parent 6bd033d commit 123809c

26 files changed

+1069
-945
lines changed

qmlboxmodel/CMakeLists.txt renamed to .archive/qmlboxmodel/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ albert_plugin(
66
SOURCE_FILES
77
${PROJECT_NAME}.qrc
88
resources/qml/*
9-
src/*.cpp
10-
src/*.h
119
src/configwidget.ui
10+
src/imageprovider*
11+
src/plugin*
12+
src/qmlinterface*
13+
src/window*
1214
PRIVATE_LINK_LIBRARIES
1315
Qt6::Qml
1416
Qt6::Quick
1517
)
1618

19+
target_sources(qmlboxmodel
20+
PRIVATE
21+
resources/qml/StateChart.scxml
22+
)
23+
1724
#install(DIRECTORY "styles/" DESTINATION "${CMAKE_INSTALL_DATADIR}/albert/${PROJECT_NAME}/styles")
1825

1926

File renamed without changes.
File renamed without changes.

qmlboxmodel/resources/qml/DefaultStyle.qml renamed to .archive/qmlboxmodel/resources/qml/DefaultStyle.qml

Lines changed: 150 additions & 108 deletions
Large diffs are not rendered by default.

qmlboxmodel/resources/qml/DesktopListView.qml renamed to .archive/qmlboxmodel/resources/qml/DesktopListView.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "albert.js" as Util
77
ListView {
88
id: resizingListView
99
objectName: "resizingListView"
10+
property int maxItems: 5
1011

1112
signal itemActivated(int index)
1213

@@ -15,7 +16,18 @@ ListView {
1516
highlightMoveDuration : 0
1617
highlightMoveVelocity : -1
1718
snapMode: ListView.SnapToItem
18-
onModelChanged: if (model && model.rowCount() > 0) currentIndex = 0
19+
onCountChanged: {
20+
// count is not guaranteed to equal the contentItem.children.length
21+
// Especially invisible do not necessarily have to exist
22+
// never let the list have height 0
23+
visible=(count !== 0)
24+
if (count !== 0)
25+
{
26+
height = Math.min(maxItems, count) * (contentItem.children[0].height + spacing) - spacing
27+
if (currentIndex < 0)
28+
currentIndex = 0
29+
}
30+
}
1931

2032
Keys.onPressed: (event)=>{
2133
//Util.printKeyPress("DefaultListView", event)

qmlboxmodel/resources/qml/ResultItemDelegate.qml renamed to .archive/qmlboxmodel/resources/qml/ResultItemDelegate.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ Item {
9191
}
9292

9393
function getInputAction(){ return itemInputAction }
94+
function getActionsList(){ return itemActionsList }
9495
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import QtQuick
2+
import Qt5Compat.GraphicalEffects
3+
import QtQuick.Window 2.2 // Screen.devicePixelRatio
4+
5+
MouseArea {
6+
id: mouseArea
7+
hoverEnabled: true
8+
property alias iconColor: gearcolor.color
9+
property bool busy: false
10+
11+
Image {
12+
id: gearmask
13+
anchors.fill: parent
14+
smooth: true
15+
source: "qrc:gear.svg"
16+
sourceSize.width: width * Screen.devicePixelRatio
17+
sourceSize.height: height * Screen.devicePixelRatio
18+
visible: false
19+
}
20+
21+
Rectangle {
22+
id: gearcolor
23+
anchors.fill: parent
24+
visible: false
25+
}
26+
27+
OpacityMask {
28+
id: gear
29+
anchors.fill: parent
30+
smooth: true
31+
opacity: mouseArea.containsMouse || busy ? 1 : 0
32+
Behavior on opacity { NumberAnimation{} }
33+
cached: true
34+
source: gearcolor
35+
maskSource: gearmask
36+
RotationAnimator on rotation {
37+
loops: Animation.Infinite;
38+
from: 0; to: 360
39+
duration: 4000
40+
}
41+
}
42+
}

.archive/qmlboxmodel/src/plugin.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (c) 2023-2024 Manuel Schneider
2+
3+
#include "plugin.h"
4+
#include "ui_configwidget.h"
5+
6+
namespace {
7+
static const char* K_WND_POS = "window_position";
8+
}
9+
10+
Plugin::Plugin() : qml_interface_(this), window(qml_interface_)
11+
{
12+
auto s = settings();
13+
restore_always_on_top(s);
14+
restore_clear_on_hide(s);
15+
restore_display_system_shadow(s);
16+
restore_follow_mouse(s);
17+
restore_hide_on_close(s);
18+
restore_hide_on_focus_loss(s);
19+
restore_show_centered(s);
20+
21+
s = state();
22+
window.setPosition(s->value(K_WND_POS).toPoint());
23+
24+
connect(&window, &Window::inputChanged, this, &Plugin::inputChanged);
25+
connect(&window, &Window::visibleChanged, this, &Plugin::visibleChanged);
26+
}
27+
28+
Plugin::~Plugin()
29+
{
30+
state()->setValue(K_WND_POS, window.position());
31+
}
32+
33+
bool Plugin::isVisible() const { return window.isVisible(); }
34+
35+
void Plugin::setVisible(bool visible) { window.setVisible(visible); }
36+
37+
QString Plugin::input() const { return window.input(); }
38+
39+
void Plugin::setInput(const QString &input) { window.setInput(input); }
40+
41+
unsigned long long Plugin::winId() const { return window.winId(); }
42+
43+
QWidget* Plugin::createFrontendConfigWidget()
44+
{
45+
auto *w = new QWidget;
46+
Ui::ConfigWidget ui;
47+
ui.setupUi(w);
48+
49+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, always_on_top, ui.checkBox_onTop, setChecked, toggled)
50+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, clear_on_hide, ui.checkBox_clearOnHide, setChecked, toggled)
51+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, display_system_shadow, ui.checkBox_systemShadow, setChecked, toggled)
52+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, follow_mouse, ui.checkBox_followMouse, setChecked, toggled)
53+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, hide_on_close, ui.checkBox_hideOnClose, setChecked, toggled)
54+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, hide_on_focus_loss, ui.checkBox_hideOnFocusOut, setChecked, toggled)
55+
ALBERT_PLUGIN_PROPERTY_CONNECT(this, show_centered, ui.checkBox_center, setChecked, toggled)
56+
57+
// Themes
58+
59+
// auto fillThemesCheckBox = [this, cb=ui.comboBox_themes](){
60+
// QSignalBlocker b(cb);
61+
// cb->clear();
62+
// QStandardItemModel *model = qobject_cast<QStandardItemModel*>(cb->model()); // safe, see docs
63+
64+
// // Add disabled placeholder item
65+
// auto *item = new QStandardItem;
66+
// item->setText("Choose theme...");
67+
// item->setEnabled(false);
68+
// model->appendRow(item);
69+
70+
// cb->insertSeparator(1);
71+
72+
// // Add themes
73+
// for (const QFileInfo &fi : availableThemes()){
74+
// item = new QStandardItem;
75+
// item->setText(fi.baseName());
76+
// item->setToolTip(fi.absoluteFilePath());
77+
// model->appendRow(item);
78+
// }
79+
// };
80+
81+
// fillThemesCheckBox();
82+
83+
// connect(ui.comboBox_themes, &QComboBox::currentIndexChanged,
84+
// this, [this, cb=ui.comboBox_themes](int i){
85+
// auto theme_file_name = cb->model()->index(i,0).data(Qt::ToolTipRole).toString();
86+
// applyTheme(theme_file_name);
87+
// });
88+
89+
// connect(ui.toolButton_propertyEditor, &QToolButton::clicked, this, [this, w](){
90+
// PropertyEditor *pe = new PropertyEditor(this, w);
91+
// pe->setWindowModality(Qt::WindowModality::WindowModal);
92+
// pe->show();
93+
// });
94+
95+
// connect(ui.toolButton_save, &QToolButton::clicked, this, [this, w, fillThemesCheckBox](){
96+
// if (auto text = QInputDialog::getText(w, qApp->applicationDisplayName(), "Theme name:"); !text.isNull()){
97+
// if (text.isEmpty())
98+
// QMessageBox::warning(w, qApp->applicationDisplayName(), "Theme name must not be empty.");
99+
// else if (auto dir = configDir(); dir.exists(text+".theme"))
100+
// QMessageBox::warning(w, qApp->applicationDisplayName(), "Theme already exists.");
101+
// else{
102+
// saveThemeAsFile(dir.filePath(text));
103+
// fillThemesCheckBox();
104+
// }
105+
// }
106+
// });
107+
108+
109+
return w;
110+
}
111+
112+
void Plugin::setQuery(albert::Query *query) { qml_interface_.setQuery(query); }
113+
114+
bool Plugin::always_on_top() const
115+
{ return window.flags() & Qt::WindowStaysOnTopHint; }
116+
117+
void Plugin::set_always_on_top_(bool value)
118+
{ window.setFlags(window.flags().setFlag(Qt::WindowStaysOnTopHint, value)); }
119+
120+
bool Plugin::display_system_shadow() const
121+
{ return !window.flags().testFlag(Qt::NoDropShadowWindowHint); }
122+
123+
void Plugin::set_display_system_shadow_(bool value)
124+
{ window.setFlags(window.flags().setFlag(Qt::NoDropShadowWindowHint, !value)); }
125+
126+
127+
128+
129+

.archive/qmlboxmodel/src/plugin.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2023-2024 Manuel Schneider
2+
3+
#pragma once
4+
#include "albert/extension/frontend/frontend.h"
5+
#include "albert/plugin.h"
6+
#include "qmlinterface.h"
7+
#include "window.h"
8+
#include <QSettings>
9+
10+
class Plugin : public albert::Frontend, public albert::PluginInstance
11+
{
12+
Q_OBJECT
13+
ALBERT_PLUGIN
14+
15+
public:
16+
17+
Plugin();
18+
~Plugin();
19+
20+
// albert::Frontend
21+
bool isVisible() const override;
22+
void setVisible(bool visible) override;
23+
QString input() const override;
24+
void setInput(const QString&) override;
25+
unsigned long long winId() const override;
26+
QWidget* createFrontendConfigWidget() override;
27+
void setQuery(albert::Query *query) override;
28+
29+
protected:
30+
31+
QmlInterface qml_interface_;
32+
Window window;
33+
34+
ALBERT_PLUGIN_PROPERTY_BASE(bool, always_on_top, true)
35+
bool always_on_top() const;
36+
void set_always_on_top_(bool value);
37+
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, clear_on_hide, window.clear_on_hide, true)
38+
ALBERT_PLUGIN_PROPERTY_BASE(bool, display_system_shadow, true)
39+
bool display_system_shadow() const;
40+
void set_display_system_shadow_(bool value);
41+
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, follow_mouse, window.follow_mouse, true)
42+
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, hide_on_close, window.hide_on_close, true)
43+
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, hide_on_focus_loss, window.hide_on_focus_loss, true)
44+
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, show_centered, window.show_centered, true)
45+
46+
};
47+
48+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2023-2024 Manuel Schneider
2+
3+
#include "albert/albert.h"
4+
#include "albert/extension/frontend/query.h"
5+
#include "albert/logging.h"
6+
#include "plugin.h"
7+
#include "qmlinterface.h"
8+
9+
#include <QStringListModel>
10+
using namespace albert;
11+
12+
QmlInterface::QmlInterface(Plugin *plugin) : plugin_(plugin) { }
13+
14+
void QmlInterface::showSettings()
15+
{
16+
plugin_->setVisible(false);
17+
albert::showSettings();
18+
}
19+
20+
QObject *QmlInterface::currentQuery() { return currentQuery_; }
21+
22+
QString QmlInterface::kcString(int kc) { return QKeySequence(kc).toString(); }
23+
24+
void QmlInterface::debug(QString m) { DEBG << m; }
25+
void QmlInterface::info(QString m) { INFO << m; }
26+
void QmlInterface::warning(QString m) { WARN << m; }
27+
void QmlInterface::critical(QString m) { CRIT << m; }
28+
29+
QAbstractListModel *QmlInterface::createStringListModel(const QStringList &action_names) const
30+
{ return new QStringListModel(action_names); }
31+
32+
void QmlInterface::setQuery(Query *q)
33+
{
34+
CRIT << "QmlInterface::setQuery";
35+
36+
if(currentQuery_)
37+
disconnect(currentQuery_, &Query::finished,
38+
this, &QmlInterface::currentQueryFinished);
39+
40+
CRIT << "das";
41+
42+
// important for qml ownership determination
43+
if (q)
44+
q->setParent(this);
45+
CRIT << "noch";
46+
47+
currentQuery_ = q;
48+
emit currentQueryChanged();
49+
CRIT << "geschafft";
50+
51+
52+
if (q)
53+
{
54+
if (q->isFinished())
55+
emit currentQueryFinished();
56+
else
57+
connect(q, &Query::finished, this, &QmlInterface::currentQueryFinished);
58+
}
59+
60+
CRIT << "!";
61+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2023-2024 Manuel Schneider
2+
3+
#pragma once
4+
#include <QAbstractListModel>
5+
#include <QObject>
6+
#include <QString>
7+
class Plugin;
8+
namespace albert { class Query; }
9+
10+
11+
class QmlInterface : public QObject
12+
{
13+
Q_OBJECT
14+
Q_PROPERTY(QObject* currentQuery_ READ currentQuery NOTIFY currentQueryChanged)
15+
16+
public:
17+
QmlInterface(Plugin *plugin);
18+
19+
Q_INVOKABLE void showSettings();
20+
Q_INVOKABLE QObject *currentQuery();
21+
Q_INVOKABLE QString kcString(int kc);
22+
23+
Q_INVOKABLE void debug(QString m);
24+
Q_INVOKABLE void info(QString m);
25+
Q_INVOKABLE void warning(QString m);
26+
Q_INVOKABLE void critical(QString m);
27+
28+
Q_INVOKABLE QAbstractListModel *createStringListModel(const QStringList &action_names) const;
29+
30+
void setQuery(albert::Query *q);
31+
32+
private:
33+
Plugin *plugin_;
34+
albert::Query *currentQuery_;
35+
36+
signals:
37+
void currentQueryChanged();
38+
void currentQueryFinished(); // convenience signal to avoid the boilerplate in qml
39+
40+
};
41+

0 commit comments

Comments
 (0)