diff --git a/CMakeLists.txt b/CMakeLists.txt index a27a12a74..ad114aed3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,12 @@ if(SPACER_PLUGIN) add_subdirectory(plugin-spacer) endif() +setByDefault(NOTES_PLUGIN Yes) +if(NOTES_PLUGIN) + list(APPEND ENABLED_PLUGINS "Notes") + add_subdirectory(plugin-notes) +endif() + ######################################################################### message(STATUS "**************** The following plugins will be built ****************") diff --git a/plugin-notes/CMakeLists.txt b/plugin-notes/CMakeLists.txt new file mode 100644 index 000000000..7bab890f3 --- /dev/null +++ b/plugin-notes/CMakeLists.txt @@ -0,0 +1,28 @@ +set(PLUGIN "notes") + +set(HEADERS + notes.h + stickynote.h + notesconfiguration.h +) + +set(SOURCES + notes.cpp + stickynote.cpp + notesconfiguration.cpp +) + +set(UIS + stickynote.ui + notesconfiguration.ui +) + +set(RESOURCES + resources.qrc +) + +set(LIBRARIES + lxqt +) + +BUILD_LXQT_PLUGIN(${PLUGIN}) diff --git a/plugin-notes/notes.cpp b/plugin-notes/notes.cpp new file mode 100644 index 000000000..28b7ef464 --- /dev/null +++ b/plugin-notes/notes.cpp @@ -0,0 +1,225 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "notes.h" +#include "notesconfiguration.h" +#include "stickynote.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Notes::Notes(const ILXQtPanelPluginStartupInfo &startupInfo) : + QObject(), + ILXQtPanelPlugin(startupInfo), + mHidden(false) +{ + realign(); + + QAction *addNew = new QAction(tr("New Note")); + QAction *showHide = new QAction(tr("Show/Hide Notes")); + + connect(addNew, &QAction::triggered, this, &Notes::addNewNote); + connect(showHide, &QAction::triggered, this, &Notes::toggleShowHide); + + QMenu *menu = new QMenu; + menu->addAction(addNew); + menu->addAction(showHide); + + mButton.setMenu(menu); + mButton.setPopupMode(QToolButton::InstantPopup); + mButton.setAutoRaise(true); + mButton.setIcon(XdgIcon::fromTheme("date", "date")); + + + // load all notes + QDir dir(dataDir()); + QStringList notes = dir.entryList(QDir::Files); + + for(int i = 0; i < notes.size(); ++i) { + qint64 noteId = notes[i].toLong(); + + if(!noteId) + continue; + + StickyNote *note = new StickyNote(noteId, &window); + connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); + + mNotes[noteId] = note; + } + + // set colors & fonts + settingsChanged(); +} + + +Notes::~Notes() +{ + for(auto it = mNotes.begin(); it != mNotes.end(); ++it) + delete it.value(); + + mNotes.clear(); +} + +void Notes::realign() +{ + mButton.setFixedHeight(panel()->iconSize()); + mButton.setFixedWidth(panel()->iconSize()); +} + + +QString Notes::dataDir() +{ + QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + "lxqt-notes"; + return dir; +} + +void Notes::addNewNote() +{ + StickyNote *note = new StickyNote(0, &window); + connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); + + QFont font = qvariant_cast(settings()->value("defaultFont")); + QString bgColor = settings()->value("backgroundColor", "#ffff7f").toString(); + QString fgColor = settings()->value("foregroundColor", "#000000").toString(); + bool showFrame = settings()->value("showWindowFrame", "false").toBool(); + + note->setFont(font); + note->setColors(bgColor, fgColor); + + if(!showFrame) + note->setWindowFlags(Qt::Window | Qt::Tool | Qt::FramelessWindowHint); + else + note->setWindowFlags(Qt::Window | Qt::Tool); + + mNotes[note->id()] = note; + note->show(); +} + +void Notes::deleteNote(const qint64 &id) +{ + auto it = mNotes.find(id); + if(it != mNotes.end()) { + delete it.value(); + mNotes.erase(it); + } + + // delete note file + QDir dir(dataDir()); + dir.remove(QString::number(id)); +} + +void Notes::toggleShowHide() +{ + if(mHidden) { + for(auto it = mNotes.begin(); it != mNotes.end(); ++it) + it.value()->show(); + mHidden = false; + } else { + for(auto it = mNotes.begin(); it != mNotes.end(); ++it) + it.value()->hide(); + mHidden = true; + } +} + +void Notes::setIconColor(const QString &icon, const QString &color) +{ + // create icons path + QString iconsDir = dataDir() + QDir::separator() + "icons"; + QDir().mkpath(iconsDir); + + // set icon color + QFile file(icon); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + QString svg = in.readAll().arg(color); + + file.close(); + + QFileInfo info(icon); + QString iconFile = iconsDir + QDir::separator() + info.fileName(); + + QFile outFile(iconFile); + if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + QTextStream out(&outFile); + out << svg; + + outFile.close(); +} + +void Notes::settingsChanged() +{ + // new params + QFont font = qvariant_cast(settings()->value("defaultFont")); + QString bgColor = settings()->value("backgroundColor", "#ffff7f").toString(); + QString fgColor = settings()->value("foregroundColor", "#000000").toString(); + bool showFrame = settings()->value("showWindowFrame","false").toBool(); + mHidden = !(settings()->value("showNotesOnStartup","false").toBool()); + + setIconColor(":/resources/times-solid.svg", fgColor); + setIconColor(":/resources/font-solid.svg", fgColor); + + for(auto it = mNotes.begin(); it != mNotes.end(); ++it) { + StickyNote *note = it.value(); + + if(!note->hasOwnFont()) + note->setFont(font); + + note->setColors(bgColor, fgColor); + + if(!showFrame) + note->setWindowFlags(Qt::Window | Qt::Tool | Qt::FramelessWindowHint); + else + note->setWindowFlags(Qt::Window | Qt::Tool); + + if(!mHidden) + note->show(); + } +} + +QDialog* Notes::configureDialog() +{ + NotesConfiguration *configDialog = new NotesConfiguration(settings()); + configDialog->setAttribute(Qt::WA_DeleteOnClose, true); + return configDialog; +} diff --git a/plugin-notes/notes.h b/plugin-notes/notes.h new file mode 100644 index 000000000..9e4c45be2 --- /dev/null +++ b/plugin-notes/notes.h @@ -0,0 +1,91 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef LXQT_NOTES_H +#define LXQT_NOTES_H + +#include "../panel/ilxqtpanelplugin.h" +#include +#include +#include +#include +#include +#include +#include +#include + +class StickyNote; + +class Notes : public QObject, public ILXQtPanelPlugin +{ + Q_OBJECT +public: + explicit Notes(const ILXQtPanelPluginStartupInfo &startupInfo); + ~Notes(); + + virtual QWidget *widget() { return &mButton; } + virtual QString themeId() const { return "Notes"; } + virtual ILXQtPanelPlugin::Flags flags() const { return HaveConfigDialog; } + + bool isSeparate() const { return true; } + QDialog *configureDialog(); + +public slots: + void realign(); + void toggleShowHide(); + void addNewNote(); + void deleteNote(const qint64 &id); + +protected slots: + void settingsChanged(); + +private: + QToolButton mButton; + bool mHidden; + QMap mNotes; + QString dataDir(); // (cannot be static for some reason) + + void setIconsColor(const QString &color); + void setIconColor(const QString &icon, const QString &color); + + QMainWindow window; +}; + + +class NotesLibrary: public QObject, public ILXQtPanelPluginLibrary +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "lxqt.org/Panel/PluginInterface/3.0") + Q_INTERFACES(ILXQtPanelPluginLibrary) +public: + ILXQtPanelPlugin *instance(const ILXQtPanelPluginStartupInfo &startupInfo) const + { + return new Notes(startupInfo); + } +}; + +#endif diff --git a/plugin-notes/notesconfiguration.cpp b/plugin-notes/notesconfiguration.cpp new file mode 100644 index 000000000..9378c42ab --- /dev/null +++ b/plugin-notes/notesconfiguration.cpp @@ -0,0 +1,123 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "notesconfiguration.h" +#include "ui_notesconfiguration.h" + +#include +#include + +NotesConfiguration::NotesConfiguration(PluginSettings *settings, QWidget *parent) : + LXQtPanelPluginConfigDialog(settings, parent), + ui(new Ui::NotesConfiguration) +{ + ui->setupUi(this); + + connect(ui->dialogButtons, &QDialogButtonBox::clicked, this, &NotesConfiguration::dialogButtonsAction); + + loadSettings(); +} + +NotesConfiguration::~NotesConfiguration() +{ + delete ui; +} + +void NotesConfiguration::on_changeFont_clicked(bool checked) +{ + bool ok; + QFont font = QFontDialog::getFont(&ok, QFont(), this); + + if(ok) { + settings().setValue("defaultFont", font); + setFont(font); + } +} + +void NotesConfiguration::on_bgColorButton_clicked(bool checked) +{ + QColor color = QColorDialog::getColor(Qt::yellow, this, "Select Backgroung Color"); + settings().setValue("backgroundColor", color.name()); + setBgColor(color); +} + +void NotesConfiguration::on_fgColorButton_clicked(bool checked) +{ + QColor color = QColorDialog::getColor(Qt::yellow, this, "Select Backgroung Color"); + settings().setValue("foregroundColor", color.name()); + setFgColor(color); +} + +void NotesConfiguration::on_showWindowFrame_toggled(bool checked) +{ + settings().setValue("showWindowFrame", checked); +} + +void NotesConfiguration::on_showNotesOnStartup_toggled(bool checked) +{ + settings().setValue("showNotesOnStartup", checked); +} + +void NotesConfiguration::setFont(const QFont &font) +{ + ui->displayFont->setText(font.family()); + ui->displayFont->setFont(font); +} + +void NotesConfiguration::setBgColor(const QColor &color) +{ + QPalette pal = ui->bgColorButton->palette(); + pal.setColor(QPalette::Button, color); + ui->bgColorButton->setAutoFillBackground(true); + ui->bgColorButton->setPalette(pal); + ui->bgColorButton->update(); +} + +void NotesConfiguration::setFgColor(const QColor &color) +{ + QPalette pal = ui->fgColorButton->palette(); + pal.setColor(QPalette::Button, color); + ui->fgColorButton->setAutoFillBackground(true); + ui->fgColorButton->setPalette(pal); + ui->fgColorButton->update(); +} + +void NotesConfiguration::loadSettings() +{ + QColor bgColorName = settings().value("backgroundColor", "#ffff7f").toString(); + QColor fgColorName = settings().value("foregroundColor", "#000000").toString(); + setBgColor(QColor(bgColorName)); + setFgColor(QColor(fgColorName)); + + QFont font = qvariant_cast(settings().value("defaultFont")); + setFont(font); + + bool showFrame = settings().value("showWindowFrame", "false").toBool(); + bool showOnStartup = settings().value("showNotesOnStartup", "false").toBool(); + ui->showWindowFrame->setChecked(showFrame); + ui->showNotesOnStartup->setChecked(showOnStartup); +} diff --git a/plugin-notes/notesconfiguration.h b/plugin-notes/notesconfiguration.h new file mode 100644 index 000000000..cedb9a05b --- /dev/null +++ b/plugin-notes/notesconfiguration.h @@ -0,0 +1,66 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef NOTESCONFIGURATION_H +#define NOTESCONFIGURATION_H + +#include + +#include "../panel/lxqtpanelpluginconfigdialog.h" +#include "../panel/pluginsettings.h" + +namespace Ui { +class NotesConfiguration; +} + +class NotesConfiguration : public LXQtPanelPluginConfigDialog +{ + Q_OBJECT + +public: + explicit NotesConfiguration(PluginSettings *settings, QWidget *parent = nullptr); + ~NotesConfiguration(); + +public slots: + void on_changeFont_clicked(bool checked = true); + void on_bgColorButton_clicked(bool checked = true); + void on_fgColorButton_clicked(bool checked = true); + void on_showWindowFrame_toggled(bool checked); + void on_showNotesOnStartup_toggled(bool checked); + +private slots: + void loadSettings(); + +private: + Ui::NotesConfiguration *ui; + + void setBgColor(const QColor &color); + void setFgColor(const QColor &color); + void setFont(const QFont &font); +}; + +#endif // NOTESCONFIGURATION_H diff --git a/plugin-notes/notesconfiguration.ui b/plugin-notes/notesconfiguration.ui new file mode 100644 index 000000000..205e2e244 --- /dev/null +++ b/plugin-notes/notesconfiguration.ui @@ -0,0 +1,130 @@ + + + NotesConfiguration + + + + 0 + 0 + 184 + 259 + + + + + 0 + 0 + + + + Dialog + + + + + + Colors + + + + + + + 0 + 0 + + + + Background + + + + + + + + + + + + + + + 0 + 0 + + + + Foreground + + + + + + + + + + + + + + + + + Show window frame + + + + + + + + + + Qt::AlignCenter + + + + + + + Show notes on startup + + + true + + + + + + + QDialogButtonBox::Ok|QDialogButtonBox::Reset + + + + + + + Default font + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/plugin-notes/resources.qrc b/plugin-notes/resources.qrc new file mode 100644 index 000000000..d89ae4f21 --- /dev/null +++ b/plugin-notes/resources.qrc @@ -0,0 +1,6 @@ + + + resources/font-solid.svg + resources/times-solid.svg + + diff --git a/plugin-notes/resources/font-solid.svg b/plugin-notes/resources/font-solid.svg new file mode 100644 index 000000000..d1ba4e045 --- /dev/null +++ b/plugin-notes/resources/font-solid.svg @@ -0,0 +1 @@ + diff --git a/plugin-notes/resources/notes.desktop.in b/plugin-notes/resources/notes.desktop.in new file mode 100644 index 000000000..7a233a47c --- /dev/null +++ b/plugin-notes/resources/notes.desktop.in @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Service +ServiceTypes=LXQtPanel/Plugin +Name=Notes +Comment=Sticky notes on Desktop. +Icon=date + +#TRANSLATIONS_DIR=../translations diff --git a/plugin-notes/resources/times-solid.svg b/plugin-notes/resources/times-solid.svg new file mode 100644 index 000000000..0b237c8b6 --- /dev/null +++ b/plugin-notes/resources/times-solid.svg @@ -0,0 +1 @@ + diff --git a/plugin-notes/stickynote.cpp b/plugin-notes/stickynote.cpp new file mode 100644 index 000000000..512d991bb --- /dev/null +++ b/plugin-notes/stickynote.cpp @@ -0,0 +1,229 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "stickynote.h" +#include "ui_stickynote.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +StickyNote::StickyNote(qint64 id, QWidget *parent): + QWidget(parent), + prevPosSet(false), + mHasOwnFont(false), + ui(new Ui::StickyNote) +{ + ui->setupUi(this); + + QString buttonStyle = "QToolButton {" + "border: 0px;" + "border-radius: 0px;" + "}"; + + QString textStyle = "QTextEdit {" + "border: 0px;" + "border-radius: 0px;" + "}"; + + ui->deleteButton->setStyleSheet(buttonStyle); + ui->fontButton->setStyleSheet(buttonStyle); + ui->textEdit->setStyleSheet(textStyle); + + connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(saveText())); + connect(ui->fontButton, SIGNAL(clicked()), this, SLOT(changeFont())); + connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(requestDelete())); + + if(id) { + mId = id; + load(); + } else { + mId = QDateTime::currentSecsSinceEpoch(); + } + + QDateTime timestamp; + timestamp.setTime_t(mId); + ui->title->setText(timestamp.toString("dd.MM.yyyy-HH:mm")); +} + +StickyNote::~StickyNote() +{ + delete ui; +} + +void StickyNote::changeFont() +{ + bool ok; + QFont font = QFontDialog::getFont(&ok, QFont()); + + if(ok) { + // store choosen font + QString dataFile = dataDir() + QDir::separator() + QString::number(mId); + QSettings settings(dataFile, QSettings::IniFormat); + settings.setValue("font", font); + + setFont(font); + + mHasOwnFont = true; + } +} + +void StickyNote::setFont(const QFont &font) +{ + ui->textEdit->setFont(font); + //ui->title->setFont(font); +} + +void StickyNote::setColors(const QString &backGround, const QString &foreground) +{ + // set bg color & textcolor + QString widgetStyle = QString("StickyNote {" + "background: %1;" + "}").arg(backGround); + + QString textEditStyle = QString("QTextEdit {" + "border: 0px;" + "background: %1;" + "}").arg(backGround); + + QString labelStyle = QString("QLabel {" + "color: %1;" + "}").arg(foreground); + + setStyleSheet(widgetStyle); + ui->textEdit->setStyleSheet(textEditStyle); + ui->textEdit->setTextColor(QColor(foreground)); + ui->title->setStyleSheet(labelStyle); + + // reset text + QString dataFile = dataDir() + QDir::separator() + QString::number(mId); + QSettings settings(dataFile, QSettings::IniFormat); + ui->textEdit->setPlainText(settings.value("text","").toString()); + + // set new icons + QString iconsDir = dataDir() + QDir::separator() + "icons"; + QString deleteIcon = iconsDir + QDir::separator() + "times-solid.svg"; + QString fontIcons = iconsDir + QDir::separator() + "font-solid.svg"; + + ui->deleteButton->setIcon(QIcon(deleteIcon)); + ui->fontButton->setIcon(QIcon(fontIcons)); +} + +void StickyNote::requestDelete() +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, tr("Delete Note"), + tr("Delete this note?"), + QMessageBox::Yes|QMessageBox::No); + + if(reply == QMessageBox::Yes) + emit deleteRequested(mId); +} + +void StickyNote::load() +{ + QString dataFile = dataDir() + QDir::separator() + QString::number(mId); + QSettings settings(dataFile, QSettings::IniFormat); + + // load current position + QSize size = qvariant_cast(settings.value("size")); + QPoint position = qvariant_cast(settings.value("position")); + move(position); + resize(size); + + // load current text + ui->textEdit->setPlainText(settings.value("text","").toString()); + + // load font settings + QString font = settings.value("font","").toString(); + if(!font.isEmpty()) { + QFont font = qvariant_cast(settings.value("font")); + ui->textEdit->setFont(font); + + mHasOwnFont = true; + } +} + +void StickyNote::saveText() +{ + QString dataFile = dataDir() + QDir::separator() + QString::number(mId); + QSettings settings(dataFile, QSettings::IniFormat); + settings.setValue("text", ui->textEdit->toPlainText()); +} + +void StickyNote::savePosition() +{ + QString dataFile = dataDir() + QDir::separator() + QString::number(mId); + QSettings settings(dataFile, QSettings::IniFormat); + settings.setValue("position",mapToGlobal(rect().topLeft())); + settings.setValue("size",rect().size()); +} + +QString StickyNote::dataDir() +{ + QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + "lxqt-notes"; + return dir; +} + +void StickyNote::resizeEvent(QResizeEvent *event) +{ + savePosition(); +} + +void StickyNote::moveEvent(QMoveEvent *event) +{ + savePosition(); +} + +void StickyNote::mouseMoveEvent(QMouseEvent *event) +{ + if(!prevPosSet) { + prevPos = event->pos(); + prevPosSet = true; + } else { + QRect geometry = this->geometry(); + QPoint pos = event->pos() - prevPos; + move(x() + pos.x(), y() + pos.y()); + } +} + +void StickyNote::mouseReleaseEvent(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) { + if(prevPosSet) { + prevPosSet = false; + savePosition(); + } + } +} diff --git a/plugin-notes/stickynote.h b/plugin-notes/stickynote.h new file mode 100644 index 000000000..6a210d8a3 --- /dev/null +++ b/plugin-notes/stickynote.h @@ -0,0 +1,81 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Matteo Fois + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef LXQT_STICKY_H +#define LXQT_STICKY_H + +#include + +namespace Ui { +class StickyNote; +} + +class StickyNote: public QWidget +{ + Q_OBJECT +public: + StickyNote(qint64 id = 0, QWidget* parent = nullptr); + ~StickyNote(); + + qint64 id() { return mId; } + + bool hasOwnFont() { return mHasOwnFont; } + +public slots: + void changeFont(); + void setColors(const QString &backGround, const QString &foreground); + void setFont(const QFont &font); + void requestDelete(); + void savePosition(); + void saveText(); + +signals: + void deleteRequested(qint64 id); + +protected: + void resizeEvent(QResizeEvent *event); + void moveEvent(QMoveEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + +private: + void load(); + + QString dataDir(); // GenericDataLocation + + qint64 mId; + + QPoint prevPos; + bool prevPosSet; + + bool mHasOwnFont; + + Ui::StickyNote *ui; +}; + + +#endif diff --git a/plugin-notes/stickynote.ui b/plugin-notes/stickynote.ui new file mode 100644 index 000000000..f01798229 --- /dev/null +++ b/plugin-notes/stickynote.ui @@ -0,0 +1,100 @@ + + + StickyNote + + + + 0 + 0 + 281 + 326 + + + + Form + + + + 6 + + + 6 + + + 6 + + + 6 + + + 0 + + + + + 0 + + + + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + + + + + + + + + + + +