Skip to content

Commit

Permalink
[qmlboxmodel] archive wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSchneid3r committed Feb 29, 2024
1 parent 6bd033d commit 123809c
Show file tree
Hide file tree
Showing 26 changed files with 1,069 additions and 945 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ albert_plugin(
SOURCE_FILES
${PROJECT_NAME}.qrc
resources/qml/*
src/*.cpp
src/*.h
src/configwidget.ui
src/imageprovider*
src/plugin*
src/qmlinterface*
src/window*
PRIVATE_LINK_LIBRARIES
Qt6::Qml
Qt6::Quick
)

target_sources(qmlboxmodel
PRIVATE
resources/qml/StateChart.scxml
)

#install(DIRECTORY "styles/" DESTINATION "${CMAKE_INSTALL_DATADIR}/albert/${PROJECT_NAME}/styles")


File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "albert.js" as Util
ListView {
id: resizingListView
objectName: "resizingListView"
property int maxItems: 5

signal itemActivated(int index)

Expand All @@ -15,7 +16,18 @@ ListView {
highlightMoveDuration : 0
highlightMoveVelocity : -1
snapMode: ListView.SnapToItem
onModelChanged: if (model && model.rowCount() > 0) currentIndex = 0
onCountChanged: {
// count is not guaranteed to equal the contentItem.children.length
// Especially invisible do not necessarily have to exist
// never let the list have height 0
visible=(count !== 0)
if (count !== 0)
{
height = Math.min(maxItems, count) * (contentItem.children[0].height + spacing) - spacing
if (currentIndex < 0)
currentIndex = 0
}
}

Keys.onPressed: (event)=>{
//Util.printKeyPress("DefaultListView", event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ Item {
}

function getInputAction(){ return itemInputAction }
function getActionsList(){ return itemActionsList }
}
42 changes: 42 additions & 0 deletions .archive/qmlboxmodel/resources/qml/SettingsButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import QtQuick
import Qt5Compat.GraphicalEffects
import QtQuick.Window 2.2 // Screen.devicePixelRatio

MouseArea {
id: mouseArea
hoverEnabled: true
property alias iconColor: gearcolor.color
property bool busy: false

Image {
id: gearmask
anchors.fill: parent
smooth: true
source: "qrc:gear.svg"
sourceSize.width: width * Screen.devicePixelRatio
sourceSize.height: height * Screen.devicePixelRatio
visible: false
}

Rectangle {
id: gearcolor
anchors.fill: parent
visible: false
}

OpacityMask {
id: gear
anchors.fill: parent
smooth: true
opacity: mouseArea.containsMouse || busy ? 1 : 0
Behavior on opacity { NumberAnimation{} }
cached: true
source: gearcolor
maskSource: gearmask
RotationAnimator on rotation {
loops: Animation.Infinite;
from: 0; to: 360
duration: 4000
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions .archive/qmlboxmodel/src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) 2023-2024 Manuel Schneider

#include "plugin.h"
#include "ui_configwidget.h"

namespace {
static const char* K_WND_POS = "window_position";
}

Plugin::Plugin() : qml_interface_(this), window(qml_interface_)
{
auto s = settings();
restore_always_on_top(s);
restore_clear_on_hide(s);
restore_display_system_shadow(s);
restore_follow_mouse(s);
restore_hide_on_close(s);
restore_hide_on_focus_loss(s);
restore_show_centered(s);

s = state();
window.setPosition(s->value(K_WND_POS).toPoint());

connect(&window, &Window::inputChanged, this, &Plugin::inputChanged);
connect(&window, &Window::visibleChanged, this, &Plugin::visibleChanged);
}

Plugin::~Plugin()
{
state()->setValue(K_WND_POS, window.position());
}

bool Plugin::isVisible() const { return window.isVisible(); }

void Plugin::setVisible(bool visible) { window.setVisible(visible); }

QString Plugin::input() const { return window.input(); }

void Plugin::setInput(const QString &input) { window.setInput(input); }

unsigned long long Plugin::winId() const { return window.winId(); }

QWidget* Plugin::createFrontendConfigWidget()
{
auto *w = new QWidget;
Ui::ConfigWidget ui;
ui.setupUi(w);

ALBERT_PLUGIN_PROPERTY_CONNECT(this, always_on_top, ui.checkBox_onTop, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, clear_on_hide, ui.checkBox_clearOnHide, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, display_system_shadow, ui.checkBox_systemShadow, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, follow_mouse, ui.checkBox_followMouse, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, hide_on_close, ui.checkBox_hideOnClose, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, hide_on_focus_loss, ui.checkBox_hideOnFocusOut, setChecked, toggled)
ALBERT_PLUGIN_PROPERTY_CONNECT(this, show_centered, ui.checkBox_center, setChecked, toggled)

// Themes

// auto fillThemesCheckBox = [this, cb=ui.comboBox_themes](){
// QSignalBlocker b(cb);
// cb->clear();
// QStandardItemModel *model = qobject_cast<QStandardItemModel*>(cb->model()); // safe, see docs

// // Add disabled placeholder item
// auto *item = new QStandardItem;
// item->setText("Choose theme...");
// item->setEnabled(false);
// model->appendRow(item);

// cb->insertSeparator(1);

// // Add themes
// for (const QFileInfo &fi : availableThemes()){
// item = new QStandardItem;
// item->setText(fi.baseName());
// item->setToolTip(fi.absoluteFilePath());
// model->appendRow(item);
// }
// };

// fillThemesCheckBox();

// connect(ui.comboBox_themes, &QComboBox::currentIndexChanged,
// this, [this, cb=ui.comboBox_themes](int i){
// auto theme_file_name = cb->model()->index(i,0).data(Qt::ToolTipRole).toString();
// applyTheme(theme_file_name);
// });

// connect(ui.toolButton_propertyEditor, &QToolButton::clicked, this, [this, w](){
// PropertyEditor *pe = new PropertyEditor(this, w);
// pe->setWindowModality(Qt::WindowModality::WindowModal);
// pe->show();
// });

// connect(ui.toolButton_save, &QToolButton::clicked, this, [this, w, fillThemesCheckBox](){
// if (auto text = QInputDialog::getText(w, qApp->applicationDisplayName(), "Theme name:"); !text.isNull()){
// if (text.isEmpty())
// QMessageBox::warning(w, qApp->applicationDisplayName(), "Theme name must not be empty.");
// else if (auto dir = configDir(); dir.exists(text+".theme"))
// QMessageBox::warning(w, qApp->applicationDisplayName(), "Theme already exists.");
// else{
// saveThemeAsFile(dir.filePath(text));
// fillThemesCheckBox();
// }
// }
// });


return w;
}

void Plugin::setQuery(albert::Query *query) { qml_interface_.setQuery(query); }

bool Plugin::always_on_top() const
{ return window.flags() & Qt::WindowStaysOnTopHint; }

void Plugin::set_always_on_top_(bool value)
{ window.setFlags(window.flags().setFlag(Qt::WindowStaysOnTopHint, value)); }

bool Plugin::display_system_shadow() const
{ return !window.flags().testFlag(Qt::NoDropShadowWindowHint); }

void Plugin::set_display_system_shadow_(bool value)
{ window.setFlags(window.flags().setFlag(Qt::NoDropShadowWindowHint, !value)); }





48 changes: 48 additions & 0 deletions .archive/qmlboxmodel/src/plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023-2024 Manuel Schneider

#pragma once
#include "albert/extension/frontend/frontend.h"
#include "albert/plugin.h"
#include "qmlinterface.h"
#include "window.h"
#include <QSettings>

class Plugin : public albert::Frontend, public albert::PluginInstance
{
Q_OBJECT
ALBERT_PLUGIN

public:

Plugin();
~Plugin();

// albert::Frontend
bool isVisible() const override;
void setVisible(bool visible) override;
QString input() const override;
void setInput(const QString&) override;
unsigned long long winId() const override;
QWidget* createFrontendConfigWidget() override;
void setQuery(albert::Query *query) override;

protected:

QmlInterface qml_interface_;
Window window;

ALBERT_PLUGIN_PROPERTY_BASE(bool, always_on_top, true)
bool always_on_top() const;
void set_always_on_top_(bool value);
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, clear_on_hide, window.clear_on_hide, true)
ALBERT_PLUGIN_PROPERTY_BASE(bool, display_system_shadow, true)
bool display_system_shadow() const;
void set_display_system_shadow_(bool value);
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, follow_mouse, window.follow_mouse, true)
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, hide_on_close, window.hide_on_close, true)
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, hide_on_focus_loss, window.hide_on_focus_loss, true)
ALBERT_PLUGIN_PROPERTY_MEMBER(bool, show_centered, window.show_centered, true)

};


File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions .archive/qmlboxmodel/src/qmlinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2023-2024 Manuel Schneider

#include "albert/albert.h"
#include "albert/extension/frontend/query.h"
#include "albert/logging.h"
#include "plugin.h"
#include "qmlinterface.h"

#include <QStringListModel>
using namespace albert;

QmlInterface::QmlInterface(Plugin *plugin) : plugin_(plugin) { }

void QmlInterface::showSettings()
{
plugin_->setVisible(false);
albert::showSettings();
}

QObject *QmlInterface::currentQuery() { return currentQuery_; }

QString QmlInterface::kcString(int kc) { return QKeySequence(kc).toString(); }

void QmlInterface::debug(QString m) { DEBG << m; }
void QmlInterface::info(QString m) { INFO << m; }
void QmlInterface::warning(QString m) { WARN << m; }
void QmlInterface::critical(QString m) { CRIT << m; }

QAbstractListModel *QmlInterface::createStringListModel(const QStringList &action_names) const
{ return new QStringListModel(action_names); }

void QmlInterface::setQuery(Query *q)
{
CRIT << "QmlInterface::setQuery";

if(currentQuery_)
disconnect(currentQuery_, &Query::finished,
this, &QmlInterface::currentQueryFinished);

CRIT << "das";

// important for qml ownership determination
if (q)
q->setParent(this);
CRIT << "noch";

currentQuery_ = q;
emit currentQueryChanged();
CRIT << "geschafft";


if (q)
{
if (q->isFinished())
emit currentQueryFinished();
else
connect(q, &Query::finished, this, &QmlInterface::currentQueryFinished);
}

CRIT << "!";
}
41 changes: 41 additions & 0 deletions .archive/qmlboxmodel/src/qmlinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2023-2024 Manuel Schneider

#pragma once
#include <QAbstractListModel>
#include <QObject>
#include <QString>
class Plugin;
namespace albert { class Query; }


class QmlInterface : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* currentQuery_ READ currentQuery NOTIFY currentQueryChanged)

public:
QmlInterface(Plugin *plugin);

Q_INVOKABLE void showSettings();
Q_INVOKABLE QObject *currentQuery();
Q_INVOKABLE QString kcString(int kc);

Q_INVOKABLE void debug(QString m);
Q_INVOKABLE void info(QString m);
Q_INVOKABLE void warning(QString m);
Q_INVOKABLE void critical(QString m);

Q_INVOKABLE QAbstractListModel *createStringListModel(const QStringList &action_names) const;

void setQuery(albert::Query *q);

private:
Plugin *plugin_;
albert::Query *currentQuery_;

signals:
void currentQueryChanged();
void currentQueryFinished(); // convenience signal to avoid the boilerplate in qml

};

Loading

0 comments on commit 123809c

Please sign in to comment.