From aad454f3b8a8f0a15bda368c64e6dca581c51885 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sat, 23 Feb 2019 15:32:06 +0100 Subject: [PATCH 1/4] first commit --- CMakeLists.txt | 6 + plugin-notes/CMakeLists.txt | 28 ++ plugin-notes/notes.cpp | 252 ++++++++++++++++++ plugin-notes/notes.h | 89 +++++++ plugin-notes/notesconfiguration.cpp | 96 +++++++ plugin-notes/notesconfiguration.h | 39 +++ plugin-notes/notesconfiguration.ui | 130 +++++++++ plugin-notes/resources.qrc | 6 + .../resources/font-solid-template.svg | 1 + plugin-notes/resources/notes.desktop.in | 8 + .../resources/times-solid-template.svg | 1 + plugin-notes/stickynote.cpp | 191 +++++++++++++ plugin-notes/stickynote.h | 81 ++++++ plugin-notes/stickynote.ui | 100 +++++++ 14 files changed, 1028 insertions(+) create mode 100644 plugin-notes/CMakeLists.txt create mode 100644 plugin-notes/notes.cpp create mode 100644 plugin-notes/notes.h create mode 100644 plugin-notes/notesconfiguration.cpp create mode 100644 plugin-notes/notesconfiguration.h create mode 100644 plugin-notes/notesconfiguration.ui create mode 100644 plugin-notes/resources.qrc create mode 100644 plugin-notes/resources/font-solid-template.svg create mode 100644 plugin-notes/resources/notes.desktop.in create mode 100644 plugin-notes/resources/times-solid-template.svg create mode 100644 plugin-notes/stickynote.cpp create mode 100644 plugin-notes/stickynote.h create mode 100644 plugin-notes/stickynote.ui 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..4a7fbfb83 --- /dev/null +++ b/plugin-notes/notes.cpp @@ -0,0 +1,252 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2012 Razor team + * Authors: + * Aaron Lewis + * + * 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(); + + mButton.setAutoRaise(true); + mButton.setIcon(XdgIcon::fromTheme("date", "date")); + + QAction *addNew = new QAction(tr("New Note")); + QAction *showHide = new QAction(tr("Show/Hide Notes")); + connect(addNew, SIGNAL(triggered()), this, SLOT(addNewNote())); + connect(showHide, SIGNAL(triggered()), this, SLOT(toggleShowHide())); + + QMenu *menu = new QMenu; + menu->addAction(addNew); + menu->addAction(showHide); + mButton.setMenu(menu); + mButton.setPopupMode(QToolButton::InstantPopup); + + QString showOnStartup = settings()->value("showNotesOnStartup","").toString(); + if(!showOnStartup.isEmpty()) + mHidden = !settings()->value("showNotesOnStartup").toBool(); + + // 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); + 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(); + 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() +{ + // TODO: call note function to move to or store last known position + 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::setIconsColor(const QString &color) +{ + // create icons path + QString iconsDir = dataDir() + QDir::separator() + "icons"; + QDir().mkpath(iconsDir); + + // set delete icon color + QFile file(":/resources/times-solid-template.svg"); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ + qDebug() << "Could not open file for read"; + return; + } + + QTextStream in(&file); + QString svg = in.readAll().arg(color); + + file.close(); + + QString iconFile = iconsDir + QDir::separator() + "times-solid.svg"; + + QFile outFile(iconFile); + if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text)){ + qDebug() << "Could not open file for write"; + return; + } + + QTextStream out(&outFile); + out << svg; + + outFile.close(); + + // set font icon color + QFile file2(":/resources/font-solid-template.svg"); + + if(!file2.open(QIODevice::ReadOnly | QIODevice::Text)){ + qDebug() << "Could not open file for read"; + return; + } + + QTextStream in2(&file2); + svg = in2.readAll().arg(color); + + file2.close(); + + iconFile = iconsDir + QDir::separator() + "font-solid.svg"; + + QFile outFile2(iconFile); + if(!outFile2.open(QIODevice::WriteOnly | QIODevice::Text)){ + qDebug() << "Could not open file for read"; + return; + } + + QTextStream out2(&outFile2); + out2 << svg; + + outFile2.close(); +} + +void Notes::settingsChanged() +{ + // set 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(); + + setIconsColor(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..0a23331aa --- /dev/null +++ b/plugin-notes/notes.h @@ -0,0 +1,89 @@ +/* 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 + +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(); // GenericDataLocation (cannot be static for some reason) + void setIconsColor(const QString &color); +}; + + +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..3e80d8416 --- /dev/null +++ b/plugin-notes/notesconfiguration.cpp @@ -0,0 +1,96 @@ +#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..69df0d66a --- /dev/null +++ b/plugin-notes/notesconfiguration.h @@ -0,0 +1,39 @@ +#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..baf8e79c3 --- /dev/null +++ b/plugin-notes/resources.qrc @@ -0,0 +1,6 @@ + + + resources/font-solid-template.svg + resources/times-solid-template.svg + + diff --git a/plugin-notes/resources/font-solid-template.svg b/plugin-notes/resources/font-solid-template.svg new file mode 100644 index 000000000..d1ba4e045 --- /dev/null +++ b/plugin-notes/resources/font-solid-template.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-template.svg b/plugin-notes/resources/times-solid-template.svg new file mode 100644 index 000000000..0b237c8b6 --- /dev/null +++ b/plugin-notes/resources/times-solid-template.svg @@ -0,0 +1 @@ + diff --git a/plugin-notes/stickynote.cpp b/plugin-notes/stickynote.cpp new file mode 100644 index 000000000..79b697f45 --- /dev/null +++ b/plugin-notes/stickynote.cpp @@ -0,0 +1,191 @@ + +#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("QWidget {" + "background: %1;" + "}").arg(backGround); + + QString labelStyle = QString("QLabel {" + "color: %1;" + "}").arg(foreground); + + this->setStyleSheet(widgetStyle); + ui->textEdit->setTextColor(QColor(foreground)); + ui->title->setStyleSheet(labelStyle); + + // 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..8b66eb68d --- /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 = 0); + ~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 + + + + + + + + ... + + + + + + + + + + + + + + + From ee684f1e390ca971e36ce786b26ed61fa0a873cb Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 26 Feb 2019 22:21:08 +0100 Subject: [PATCH 2/4] Removed tabs; use new signal slot syntax; default values on all loading operations from settings; little code cleanup --- plugin-notes/notes.cpp | 217 ++++++++---------- plugin-notes/notes.h | 11 +- plugin-notes/notesconfiguration.cpp | 105 +++++---- plugin-notes/notesconfiguration.h | 37 ++- plugin-notes/resources.qrc | 4 +- ...font-solid-template.svg => font-solid.svg} | 0 ...mes-solid-template.svg => times-solid.svg} | 0 plugin-notes/stickynote.cpp | 194 +++++++++------- plugin-notes/stickynote.h | 44 ++-- 9 files changed, 338 insertions(+), 274 deletions(-) rename plugin-notes/resources/{font-solid-template.svg => font-solid.svg} (100%) rename plugin-notes/resources/{times-solid-template.svg => times-solid.svg} (100%) diff --git a/plugin-notes/notes.cpp b/plugin-notes/notes.cpp index 4a7fbfb83..62f2ef72b 100644 --- a/plugin-notes/notes.cpp +++ b/plugin-notes/notes.cpp @@ -6,7 +6,7 @@ * * Copyright: 2012 Razor team * Authors: - * Aaron Lewis + * 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 @@ -52,36 +52,36 @@ Notes::Notes(const ILXQtPanelPluginStartupInfo &startupInfo) : { realign(); - mButton.setAutoRaise(true); - mButton.setIcon(XdgIcon::fromTheme("date", "date")); - QAction *addNew = new QAction(tr("New Note")); QAction *showHide = new QAction(tr("Show/Hide Notes")); - connect(addNew, SIGNAL(triggered()), this, SLOT(addNewNote())); - connect(showHide, SIGNAL(triggered()), this, SLOT(toggleShowHide())); + + 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")); - QString showOnStartup = settings()->value("showNotesOnStartup","").toString(); - if(!showOnStartup.isEmpty()) - mHidden = !settings()->value("showNotesOnStartup").toBool(); // load all notes QDir dir(dataDir()); - QStringList notes = dir.entryList(QDir::Files); + 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); - connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); - - mNotes[noteId] = note; + qint64 noteId = notes[i].toLong(); + + if(!noteId) + continue; + + StickyNote *note = new StickyNote(noteId); + connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); + + mNotes[noteId] = note; } // set colors & fonts @@ -91,162 +91,135 @@ Notes::Notes(const ILXQtPanelPluginStartupInfo &startupInfo) : Notes::~Notes() { - for(auto it = mNotes.begin(); it != mNotes.end(); ++it) - delete it.value(); + for(auto it = mNotes.begin(); it != mNotes.end(); ++it) + delete it.value(); - mNotes.clear(); + mNotes.clear(); } void Notes::realign() { - mButton.setFixedHeight(panel()->iconSize()); + mButton.setFixedHeight(panel()->iconSize()); mButton.setFixedWidth(panel()->iconSize()); } QString Notes::dataDir() { - QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + "lxqt-notes"; - return dir; + QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + "lxqt-notes"; + return dir; } void Notes::addNewNote() { - StickyNote *note = new StickyNote(); - 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); + StickyNote *note = new StickyNote(); + 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); + note->setWindowFlags(Qt::Window | Qt::Tool | Qt::FramelessWindowHint); else - note->setWindowFlags(Qt::Window | Qt::Tool); - - mNotes[note->id()] = note; - note->show(); + 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()); + 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() { - // TODO: call note function to move to or store last known position - 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; - } + 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::setIconsColor(const QString &color) +void Notes::setIconColor(const QString &icon, const QString &color) { - // create icons path - QString iconsDir = dataDir() + QDir::separator() + "icons"; - QDir().mkpath(iconsDir); - - // set delete icon color - QFile file(":/resources/times-solid-template.svg"); - if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ - qDebug() << "Could not open file for read"; + // 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(); - QString iconFile = iconsDir + QDir::separator() + "times-solid.svg"; - + QFileInfo info(icon); + QString iconFile = iconsDir + QDir::separator() + info.fileName(); + QFile outFile(iconFile); - if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text)){ - qDebug() << "Could not open file for write"; + if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) return; - } QTextStream out(&outFile); out << svg; outFile.close(); - - // set font icon color - QFile file2(":/resources/font-solid-template.svg"); - - if(!file2.open(QIODevice::ReadOnly | QIODevice::Text)){ - qDebug() << "Could not open file for read"; - return; - } - - QTextStream in2(&file2); - svg = in2.readAll().arg(color); - - file2.close(); - - iconFile = iconsDir + QDir::separator() + "font-solid.svg"; - - QFile outFile2(iconFile); - if(!outFile2.open(QIODevice::WriteOnly | QIODevice::Text)){ - qDebug() << "Could not open file for read"; - return; - } - - QTextStream out2(&outFile2); - out2 << svg; - - outFile2.close(); } void Notes::settingsChanged() { - // set 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(); - - setIconsColor(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(); + // 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; + 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 index 0a23331aa..d36261d11 100644 --- a/plugin-notes/notes.h +++ b/plugin-notes/notes.h @@ -55,22 +55,21 @@ class Notes : public QObject, public ILXQtPanelPlugin public slots: void realign(); - void toggleShowHide(); - void addNewNote(); - void deleteNote(const qint64 &id); - + 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) - QString dataDir(); // GenericDataLocation (cannot be static for some reason) void setIconsColor(const QString &color); + void setIconColor(const QString &icon, const QString &color); }; diff --git a/plugin-notes/notesconfiguration.cpp b/plugin-notes/notesconfiguration.cpp index 3e80d8416..9378c42ab 100644 --- a/plugin-notes/notesconfiguration.cpp +++ b/plugin-notes/notesconfiguration.cpp @@ -1,3 +1,30 @@ +/* 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" @@ -22,75 +49,75 @@ NotesConfiguration::~NotesConfiguration() void NotesConfiguration::on_changeFont_clicked(bool checked) { - bool ok; - QFont font = QFontDialog::getFont(&ok, QFont(), this); - - if(ok) { - settings().setValue("defaultFont", font); - setFont(font); - } + 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); + 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); + 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); + settings().setValue("showWindowFrame", checked); } void NotesConfiguration::on_showNotesOnStartup_toggled(bool checked) { - settings().setValue("showNotesOnStartup", checked); + settings().setValue("showNotesOnStartup", checked); } void NotesConfiguration::setFont(const QFont &font) { - ui->displayFont->setText(font.family()); - ui->displayFont->setFont(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(); + 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(); + 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); + 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 index 69df0d66a..cedb9a05b 100644 --- a/plugin-notes/notesconfiguration.h +++ b/plugin-notes/notesconfiguration.h @@ -1,3 +1,30 @@ +/* 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 @@ -19,11 +46,11 @@ class NotesConfiguration : public LXQtPanelPluginConfigDialog ~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); + 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(); diff --git a/plugin-notes/resources.qrc b/plugin-notes/resources.qrc index baf8e79c3..d89ae4f21 100644 --- a/plugin-notes/resources.qrc +++ b/plugin-notes/resources.qrc @@ -1,6 +1,6 @@ - resources/font-solid-template.svg - resources/times-solid-template.svg + resources/font-solid.svg + resources/times-solid.svg diff --git a/plugin-notes/resources/font-solid-template.svg b/plugin-notes/resources/font-solid.svg similarity index 100% rename from plugin-notes/resources/font-solid-template.svg rename to plugin-notes/resources/font-solid.svg diff --git a/plugin-notes/resources/times-solid-template.svg b/plugin-notes/resources/times-solid.svg similarity index 100% rename from plugin-notes/resources/times-solid-template.svg rename to plugin-notes/resources/times-solid.svg diff --git a/plugin-notes/stickynote.cpp b/plugin-notes/stickynote.cpp index 79b697f45..512d991bb 100644 --- a/plugin-notes/stickynote.cpp +++ b/plugin-notes/stickynote.cpp @@ -1,4 +1,30 @@ - +/* 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" @@ -19,9 +45,9 @@ StickyNote::StickyNote(qint64 id, QWidget *parent): mHasOwnFont(false), ui(new Ui::StickyNote) { - ui->setupUi(this); + ui->setupUi(this); - QString buttonStyle = "QToolButton {" + QString buttonStyle = "QToolButton {" "border: 0px;" "border-radius: 0px;" "}"; @@ -40,132 +66,144 @@ StickyNote::StickyNote(qint64 id, QWidget *parent): 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")); + 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; + 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; - } + 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); + ui->textEdit->setFont(font); + //ui->title->setFont(font); } void StickyNote::setColors(const QString &backGround, const QString &foreground) { - // set bg color & textcolor - QString widgetStyle = QString("QWidget {" + // 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 {" + QString labelStyle = QString("QLabel {" "color: %1;" "}").arg(foreground); - this->setStyleSheet(widgetStyle); + setStyleSheet(widgetStyle); + ui->textEdit->setStyleSheet(textEditStyle); ui->textEdit->setTextColor(QColor(foreground)); ui->title->setStyleSheet(labelStyle); - - // 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)); + + // 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); + 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); + 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; - } + 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()); + 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 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; + QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + "lxqt-notes"; + return dir; } void StickyNote::resizeEvent(QResizeEvent *event) { - savePosition(); + savePosition(); } void StickyNote::moveEvent(QMoveEvent *event) { - savePosition(); + savePosition(); } void StickyNote::mouseMoveEvent(QMouseEvent *event) @@ -183,9 +221,9 @@ void StickyNote::mouseMoveEvent(QMouseEvent *event) void StickyNote::mouseReleaseEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { - if(prevPosSet) { - prevPosSet = false; - savePosition(); + if(prevPosSet) { + prevPosSet = false; + savePosition(); } } } diff --git a/plugin-notes/stickynote.h b/plugin-notes/stickynote.h index 8b66eb68d..9ff2fa36e 100644 --- a/plugin-notes/stickynote.h +++ b/plugin-notes/stickynote.h @@ -36,7 +36,7 @@ class StickyNote; class StickyNote: public QWidget { - Q_OBJECT + Q_OBJECT public: StickyNote(qint64 id = 0, QWidget* parent = 0); ~StickyNote(); @@ -46,35 +46,35 @@ class StickyNote: public QWidget 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(); + 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); + void deleteRequested(qint64 id); protected: - void resizeEvent(QResizeEvent *event); - void moveEvent(QMoveEvent *event); - void mouseMoveEvent(QMouseEvent *event); + void resizeEvent(QResizeEvent *event); + void moveEvent(QMoveEvent *event); + void mouseMoveEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); private: - void load(); - - QString dataDir(); // GenericDataLocation + void load(); + + QString dataDir(); // GenericDataLocation - qint64 mId; - - QPoint prevPos; - bool prevPosSet; - - bool mHasOwnFont; - - Ui::StickyNote *ui; + qint64 mId; + + QPoint prevPos; + bool prevPosSet; + + bool mHasOwnFont; + + Ui::StickyNote *ui; }; From 36e11c112a61c10b693f45db3da3dfdc21c6fb40 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sat, 2 Mar 2019 12:15:07 +0100 Subject: [PATCH 3/4] Workaround to hide taskbar entries: make stikynotes children of a fake mainwindow --- plugin-notes/notes.cpp | 4 ++-- plugin-notes/notes.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-notes/notes.cpp b/plugin-notes/notes.cpp index 62f2ef72b..28b7ef464 100644 --- a/plugin-notes/notes.cpp +++ b/plugin-notes/notes.cpp @@ -78,7 +78,7 @@ Notes::Notes(const ILXQtPanelPluginStartupInfo &startupInfo) : if(!noteId) continue; - StickyNote *note = new StickyNote(noteId); + StickyNote *note = new StickyNote(noteId, &window); connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); mNotes[noteId] = note; @@ -112,7 +112,7 @@ QString Notes::dataDir() void Notes::addNewNote() { - StickyNote *note = new StickyNote(); + StickyNote *note = new StickyNote(0, &window); connect(note, &StickyNote::deleteRequested, this, &Notes::deleteNote); QFont font = qvariant_cast(settings()->value("defaultFont")); diff --git a/plugin-notes/notes.h b/plugin-notes/notes.h index d36261d11..9e4c45be2 100644 --- a/plugin-notes/notes.h +++ b/plugin-notes/notes.h @@ -30,6 +30,7 @@ #include "../panel/ilxqtpanelplugin.h" #include +#include #include #include #include @@ -70,6 +71,8 @@ protected slots: void setIconsColor(const QString &color); void setIconColor(const QString &icon, const QString &color); + + QMainWindow window; }; From 7e0534dbcd34d6d7dec10a6f8505b347783623a0 Mon Sep 17 00:00:00 2001 From: Matteo Date: Mon, 4 Mar 2019 07:50:26 +0100 Subject: [PATCH 4/4] nullptr instead of 0 to init stickynote widget --- plugin-notes/stickynote.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-notes/stickynote.h b/plugin-notes/stickynote.h index 9ff2fa36e..6a210d8a3 100644 --- a/plugin-notes/stickynote.h +++ b/plugin-notes/stickynote.h @@ -38,7 +38,7 @@ class StickyNote: public QWidget { Q_OBJECT public: - StickyNote(qint64 id = 0, QWidget* parent = 0); + StickyNote(qint64 id = 0, QWidget* parent = nullptr); ~StickyNote(); qint64 id() { return mId; }