This commit is contained in:
Martin Rotter 2020-10-06 20:29:18 +02:00
parent 821192906e
commit 580457ae12
11 changed files with 265 additions and 8 deletions

View File

@ -0,0 +1,51 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "gui/colortoolbutton.h"
#include <QColorDialog>
#include <QPainter>
#include <QPainterPath>
ColorToolButton::ColorToolButton(QWidget* parent) : QToolButton(parent), m_color(Qt::GlobalColor::black) {
connect(this, &ColorToolButton::clicked, this, [this]() {
auto new_color = QColorDialog::getColor(m_color, parentWidget(), tr("Select new color"),
QColorDialog::ColorDialogOption::DontUseNativeDialog |
QColorDialog::ColorDialogOption::ShowAlphaChannel);
if (new_color.isValid()) {
setColor(new_color);
emit colorChanged(new_color);
}
});
}
QColor ColorToolButton::color() const {
return m_color;
}
void ColorToolButton::setColor(const QColor& color) {
m_color = color;
repaint();
}
void ColorToolButton::paintEvent(QPaintEvent* e) {
Q_UNUSED(e)
QPainter p(this);
QRect rect(QPoint(0, 0), size());
if (isEnabled()) {
if (underMouse() || isChecked()) {
p.setOpacity(0.7);
}
}
else {
p.setOpacity(0.3);
}
QPainterPath path;
path.addRoundedRect(QRectF(rect), 3, 3);
p.fillPath(path, m_color);
}

View File

@ -0,0 +1,27 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef COLORTOOLBUTTON_H
#define COLORTOOLBUTTON_H
#include <QToolButton>
class ColorToolButton : public QToolButton {
Q_OBJECT
public:
explicit ColorToolButton(QWidget* parent = nullptr);
QColor color() const;
void setColor(const QColor& color);
signals:
void colorChanged(const QColor& new_color);
protected:
virtual void paintEvent(QPaintEvent* e);
private:
QColor m_color;
};
#endif // COLORTOOLBUTTON_H

View File

@ -0,0 +1,19 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "gui/dialogs/formaddeditlabel.h"
#include "services/abstract/label.h"
FormAddEditLabel::FormAddEditLabel(QWidget* parent) : QDialog(parent), ui(new Ui::FormAddEditLabel) {
ui->setupUi(this);
}
FormAddEditLabel::~FormAddEditLabel() {
delete ui;
}
Label* FormAddEditLabel::execForAdd() {
auto exit_code = exec();
return nullptr;
}

View File

@ -0,0 +1,30 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef FORMADDEDITLABEL_H
#define FORMADDEDITLABEL_H
#include <QDialog>
#include "ui_formaddeditlabel.h"
namespace Ui {
class FormAddEditLabel;
}
class Label;
class FormAddEditLabel : public QDialog {
Q_OBJECT
public:
explicit FormAddEditLabel(QWidget* parent = nullptr);
~FormAddEditLabel();
public slots:
Label* execForAdd();
private:
Ui::FormAddEditLabel* ui;
};
#endif // FORMADDEDITLABEL_H

View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormAddEditLabel</class>
<widget class="QDialog" name="FormAddEditLabel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="widget" native="true"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="ColorToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ColorToolButton</class>
<extends>QToolButton</extends>
<header>colortoolbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FormAddEditLabel</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FormAddEditLabel</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -21,8 +21,6 @@ class PlainToolButton : public QToolButton {
void reactOnSenderActionChange();
protected:
// Custom look.
void paintEvent(QPaintEvent* e);
private:

View File

@ -47,9 +47,11 @@ HEADERS += core/feeddownloader.h \
exceptions/ioexception.h \
gui/baselineedit.h \
gui/basetoolbar.h \
gui/colortoolbutton.h \
gui/comboboxwithstatus.h \
gui/dialogs/formabout.h \
gui/dialogs/formaddaccount.h \
gui/dialogs/formaddeditlabel.h \
gui/dialogs/formbackupdatabasesettings.h \
gui/dialogs/formdatabasecleanup.h \
gui/dialogs/formmain.h \
@ -195,9 +197,11 @@ SOURCES += core/feeddownloader.cpp \
exceptions/ioexception.cpp \
gui/baselineedit.cpp \
gui/basetoolbar.cpp \
gui/colortoolbutton.cpp \
gui/comboboxwithstatus.cpp \
gui/dialogs/formabout.cpp \
gui/dialogs/formaddaccount.cpp \
gui/dialogs/formaddeditlabel.cpp \
gui/dialogs/formbackupdatabasesettings.cpp \
gui/dialogs/formdatabasecleanup.cpp \
gui/dialogs/formmain.cpp \
@ -325,6 +329,7 @@ mac {
FORMS += gui/dialogs/formabout.ui \
gui/dialogs/formaddaccount.ui \
gui/dialogs/formaddeditlabel.ui \
gui/dialogs/formbackupdatabasesettings.ui \
gui/dialogs/formdatabasecleanup.ui \
gui/dialogs/formmain.ui \

View File

@ -2,6 +2,7 @@
#include "services/abstract/labelsnode.h"
#include "gui/dialogs/formaddeditlabel.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "services/abstract/serviceroot.h"
@ -19,9 +20,17 @@ QList<QAction*> LabelsNode::contextMenuFeedsList() {
if (m_actLabelNew == nullptr) {
// Initialize it all.
m_actLabelNew = new QAction(qApp->icons()->fromTheme("tag-new"), tr("New label"), this);
connect(m_actLabelNew, &QAction::triggered, this, &LabelsNode::createLabel);
}
return QList<QAction*> {
m_actLabelNew
};
}
void LabelsNode::createLabel() {
FormAddEditLabel frm(qApp->mainFormWidget());
frm.execForAdd();
}

View File

@ -13,6 +13,9 @@ class LabelsNode : public RootItem {
virtual QList<QAction*> contextMenuFeedsList();
public slots:
void createLabel();
private:
QAction* m_actLabelNew;
};

View File

@ -153,18 +153,18 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LabelWithStatus</class>
<extends>QWidget</extends>
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_spinLimitMessages</tabstop>

View File

@ -142,6 +142,7 @@ void StandardServiceRoot::loadFromDatabase() {
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
appendChild(new LabelsNode(this));
updateCounts(true);
}