diff --git a/CMakeLists.txt b/CMakeLists.txt index e21736a..175a20f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(QAD) set(QAD_MAJOR 2) -set(QAD_MINOR 10) +set(QAD_MINOR 11) set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) diff --git a/libs/blockview/drawtools.cpp b/libs/blockview/drawtools.cpp index e013e22..5b9e344 100644 --- a/libs/blockview/drawtools.cpp +++ b/libs/blockview/drawtools.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include _DTSizeItem::_DTSizeItem(): QGraphicsObject() { diff --git a/libs/qglview/propertyeditor.cpp b/libs/qglview/propertyeditor.cpp index ed0f81b..168ad13 100644 --- a/libs/qglview/propertyeditor.cpp +++ b/libs/qglview/propertyeditor.cpp @@ -1,4 +1,5 @@ #include "propertyeditor.h" +#include QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const { diff --git a/libs/widgets/chardialog.cpp b/libs/widgets/chardialog.cpp index 5c255c0..c6e9b5e 100644 --- a/libs/widgets/chardialog.cpp +++ b/libs/widgets/chardialog.cpp @@ -85,7 +85,7 @@ void CharDialog::resizeEvent(QResizeEvent * ) { ui->tableChars->setColumnCount(c); for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { - if (ui->tableChars->item(i, j) == 0) { + if (ui->tableChars->item(i, j) == nullptr) { ui->tableChars->setItem(i, j, new QTableWidgetItem()); ui->tableChars->item(i, j)->setTextAlignment(Qt::AlignCenter); } @@ -136,7 +136,7 @@ void CharDialog::on_spinSize_valueChanged(int index) { QFont font = ui->tableChars->font(); font.setPointSize(size); ui->tableChars->setFont(font); - resizeEvent(0); + resizeEvent(nullptr); } diff --git a/libs/widgets/chardialog.h b/libs/widgets/chardialog.h index b9a28da..2c28174 100644 --- a/libs/widgets/chardialog.h +++ b/libs/widgets/chardialog.h @@ -20,10 +20,8 @@ #ifndef CHARDIALOG_H #define CHARDIALOG_H -#include -#include -#include #include "qad_widgets_export.h" +#include namespace Ui { @@ -35,26 +33,12 @@ class QAD_WIDGETS_EXPORT CharDialog: public QDialog { Q_OBJECT public: - explicit CharDialog(QWidget * parent = 0); - ~CharDialog(); + explicit CharDialog(QWidget * parent = nullptr); + ~CharDialog() override; QChar selectedChar() {return sel_char;} void setCharFont(const QFont & f); -public slots: - -private: - void changeEvent(QEvent * e); - virtual bool eventFilter(QObject * o, QEvent * e); - virtual void resizeEvent(QResizeEvent * ); - void clear(); - - Ui::CharDialog * ui; - QVector > chars; - QVector * cur; - QChar sel_char; - int size, csize; - private slots: void on_comboCategory_currentIndexChanged(int index); void on_verticalScroll_valueChanged(int index); @@ -66,7 +50,18 @@ private slots: signals: void charSelected(QChar ch); + +private: + void changeEvent(QEvent * e) override; + bool eventFilter(QObject * o, QEvent * e) override; + void resizeEvent(QResizeEvent *) override; + void clear(); + Ui::CharDialog * ui; + QVector > chars; + QVector * cur; + QChar sel_char; + int size, csize; }; #endif // CHARDIALOG_H diff --git a/libs/widgets/clineedit.cpp b/libs/widgets/clineedit.cpp index 7e6dedd..917a33f 100644 --- a/libs/widgets/clineedit.cpp +++ b/libs/widgets/clineedit.cpp @@ -1,5 +1,7 @@ #include "clineedit.h" #include "qad_types.h" +#include +#include CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) { @@ -9,7 +11,7 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) { cw->setToolTip(tr("Clear")); cw->hide(); cw->installEventFilter(this); - connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString))); + connect(this, &QLineEdit::textChanged, this, &CLineEdit::textChangedSlot); int is = fontHeight(this); QMargins m = textMargins(); m.setRight(m.right() + (is * 1.2)); @@ -17,10 +19,15 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) { } +CLineEdit::~CLineEdit() { + delete cw; +} + + bool CLineEdit::eventFilter(QObject * o, QEvent * e) { switch (e->type()) { case QEvent::MouseButtonRelease: - clearMouseRelease((QMouseEvent * )e); + clearMouseRelease(static_cast(e)); break; case QEvent::Paint: cwPaintEvent(); @@ -62,5 +69,17 @@ void CLineEdit::setDefaultText(const QString & t, bool set_text) { cw->hide(); return; } - textChanged_(text()); + textChangedSlot(text()); +} + + +void CLineEdit::clearMouseRelease(QMouseEvent *e) { + if (cw->rect().contains(e->pos())) { + clearClick(); + } +} + + +void CLineEdit::textChangedSlot(QString text) { + cw->setVisible(text != dt); } diff --git a/libs/widgets/clineedit.h b/libs/widgets/clineedit.h index 9424a74..539e19c 100644 --- a/libs/widgets/clineedit.h +++ b/libs/widgets/clineedit.h @@ -20,46 +20,40 @@ #ifndef CLINEEDIT_H #define CLINEEDIT_H -#include -#include -#include -#include #include "qad_widgets_export.h" +#include class QAD_WIDGETS_EXPORT CLineEdit: public QLineEdit { Q_OBJECT Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText) - public: - explicit CLineEdit(QWidget * parent = 0); - ~CLineEdit() {delete cw;} + explicit CLineEdit(QWidget * parent = nullptr); + ~CLineEdit() override; const QString & defaultText() const {return dt;} - -protected: - QWidget * cw; - QString dt; - QImage clear_im; - -private: - bool eventFilter(QObject * o, QEvent * e); - void resizeEvent(QResizeEvent * ); - void changeEvent(QEvent * e); - void cwPaintEvent(); - -private slots: - void clearMouseRelease(QMouseEvent * e) {if (cw->rect().contains(e->pos())) clearClick();} - void textChanged_(QString text) {cw->setVisible(text != dt);} - + public slots: void clearClick() {if (!isEnabled()) return; setText(dt); emit cleared(); emit textEdited(dt);} void setDefaultText(const QString & t, bool set_text = false); - + signals: void cleared(); - + +private slots: + void clearMouseRelease(QMouseEvent *e); + void textChangedSlot(QString text); + +private: + bool eventFilter(QObject * o, QEvent * e) override; + void resizeEvent(QResizeEvent *) override; + void changeEvent(QEvent * e) override; + void cwPaintEvent(); + + QWidget * cw; + QString dt; + QImage clear_im; }; #endif // CLINEEDIT_H diff --git a/libs/widgets/colorbutton.cpp b/libs/widgets/colorbutton.cpp index fc359de..0602ff9 100644 --- a/libs/widgets/colorbutton.cpp +++ b/libs/widgets/colorbutton.cpp @@ -1,9 +1,16 @@ #include "colorbutton.h" -#include +#include "qclipboard.h" +#include "qcolor.h" +#include "qmenu.h" +#include +#include #include #include +#include +#include -ColorButton::ColorButton(QWidget * parent): QPushButton(parent) { + +ColorButton::ColorButton(QWidget * parent): QPushButton(parent), menu(new QMenu(this)) { frame = false; options = QColorDialog::ShowAlphaChannel; back = new QWidget(this); @@ -17,10 +24,10 @@ ColorButton::ColorButton(QWidget * parent): QPushButton(parent) { label->setFrameStyle(QFrame::Panel | QFrame::Sunken); label->show(); pal = label->palette(); - a_copy = menu.addAction(QIcon(":/icons/edit-copy.png"), tr("Copy"), this, SLOT(copy())); - a_paste = menu.addAction(QIcon(":/icons/edit-paste.png"), tr("Paste"), this, SLOT(paste())); - menu.addSeparator(); - a_mix = menu.addAction(tr("Mix with clipboard"), this, SLOT(mix())); + a_copy = menu->addAction(QIcon(":/icons/edit-copy.png"), tr("Copy"), this, SLOT(copy())); + a_paste = menu->addAction(QIcon(":/icons/edit-paste.png"), tr("Paste"), this, SLOT(paste())); + menu->addSeparator(); + a_mix = menu->addAction(tr("Mix with clipboard"), this, SLOT(mix())); setAcceptDrops(true); connect(this, SIGNAL(clicked(bool)), this, SLOT(clicked())); } @@ -32,8 +39,11 @@ ColorButton::~ColorButton() { void ColorButton::resizeEvent(QResizeEvent * ) { - if (frame) back->setGeometry(rect()); - else back->setGeometry(8, 5, width() - 16, height() - 12); + if (frame) { + back->setGeometry(rect()); + } else { + back->setGeometry(8, 5, width() - 16, height() - 12); + } label->setGeometry(back->geometry()); } @@ -41,11 +51,11 @@ void ColorButton::resizeEvent(QResizeEvent * ) { void ColorButton::mousePressEvent(QMouseEvent * e) { pp = e->pos(); if (e->buttons().testFlag(Qt::RightButton)) { - menu.popup( + menu->popup( #if QT_VERSION_MAJOR <= 5 - ((QMouseEvent*)e)->globalPos() + static_cast(e)->globalPos() #else - ((QMouseEvent*)e)->globalPosition().toPoint() + static_cast(e)->globalPosition().toPoint() #endif ); return; @@ -107,15 +117,19 @@ void ColorButton::changeEvent(QEvent * e) { void ColorButton::clicked() { - QColor ret = QColorDialog::getColor(color(), nullptr, tr("Choose color"), options); - if (!ret.isValid()) return; + QColor ret = QColorDialog::getColor(color(), nullptr, tr("Choose color"), static_cast(options)); + if (!ret.isValid()) { + return; + } setColor(ret); } void ColorButton::mix() { QColor c(QApplication::clipboard()->text()); - if (!c.isValid()) return; + if (!c.isValid()) { + return; + } QColor sc = color(); setColor(QColor((c.red() + sc.red()) / 2, (c.green() + sc.green()) / 2, (c.blue() + sc.blue()) / 2, (c.alpha() + sc.alpha()) / 2)); } @@ -123,10 +137,65 @@ void ColorButton::mix() { void ColorButton::setColor(const QColor & col) { if (pal.color(label->backgroundRole()) == col) return; - if (options.testFlag(QColorDialog::ShowAlphaChannel)) + if (options & QColorDialog::ShowAlphaChannel) { pal.setColor(label->backgroundRole(), col); - else + } else { pal.setColor(label->backgroundRole(), QColor(col.red(), col.green(), col.blue())); + } label->setPalette(pal); emit colorChanged(color()); } + + +void ColorButton::setFrameOnly(bool yes) { + frame = yes; + setFlat(frame); + resizeEvent(nullptr); +} + + +QColor ColorButton::color() const { + return pal.color(label->backgroundRole()); +} + + +bool ColorButton::useNativeDialog() const { + return !(options & QColorDialog::DontUseNativeDialog); +} + + +bool ColorButton::useAlphaChannel() const { + return (options & QColorDialog::ShowAlphaChannel); +} + + +void ColorButton::setUseNativeDialog(bool yes) { + if (yes) { + options &= ~QColorDialog::DontUseNativeDialog; + } else { + options |= QColorDialog::DontUseNativeDialog; + } +} + + +void ColorButton::setUseAlphaChannel(bool yes) { + if (yes) { + options |= QColorDialog::ShowAlphaChannel; + } else { + options &= ~QColorDialog::ShowAlphaChannel; + } +} + + +void ColorButton::paste() { + QColor c(QApplication::clipboard()->text()); + if (c.isValid()) { + setColor(c); + } +} + + +void ColorButton::copy() { + QApplication::clipboard()->setText(color().name()); +} + diff --git a/libs/widgets/colorbutton.h b/libs/widgets/colorbutton.h index 5987b06..f71d8b9 100644 --- a/libs/widgets/colorbutton.h +++ b/libs/widgets/colorbutton.h @@ -20,15 +20,11 @@ #ifndef COLORBUTTON_H #define COLORBUTTON_H -#include -#include -#include -#include -#include -#include -#include -#include #include "qad_widgets_export.h" +#include + + +class QFrame; class QAD_WIDGETS_EXPORT ColorButton: public QPushButton @@ -38,48 +34,46 @@ class QAD_WIDGETS_EXPORT ColorButton: public QPushButton Q_PROPERTY(bool useNativeDialog READ useNativeDialog WRITE setUseNativeDialog) Q_PROPERTY(bool useAlphaChannel READ useAlphaChannel WRITE setUseAlphaChannel) Q_PROPERTY(bool frameOnly READ frameOnly WRITE setFrameOnly) - public: - explicit ColorButton(QWidget * parent = 0); - ~ColorButton(); + explicit ColorButton(QWidget * parent = nullptr); + ~ColorButton() override; - QColor color() const {return pal.color(label->backgroundRole());} - bool useNativeDialog() const {return !options.testFlag(QColorDialog::DontUseNativeDialog);} - bool useAlphaChannel() const {return options.testFlag(QColorDialog::ShowAlphaChannel);} + QColor color() const; + bool useNativeDialog() const; + bool useAlphaChannel() const; bool frameOnly() const {return frame;} public slots: void setColor(const QColor & col); - void setUseNativeDialog(bool yes) {if (yes) options &= ~QColorDialog::DontUseNativeDialog; else options |= QColorDialog::DontUseNativeDialog;} - void setUseAlphaChannel(bool yes) {if (yes) options |= QColorDialog::ShowAlphaChannel; else options &= ~QColorDialog::ShowAlphaChannel;} - void setFrameOnly(bool yes) {frame = yes; setFlat(frame); resizeEvent(0);} + void setUseNativeDialog(bool yes); + void setUseAlphaChannel(bool yes); + void setFrameOnly(bool yes); + +private slots: + void clicked(); + void copy(); + void paste(); + void mix(); + +signals: + void colorChanged(QColor); private: - void mousePressEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void resizeEvent(QResizeEvent * ); - void dragEnterEvent(QDragEnterEvent * e); - void dropEvent(QDropEvent * e); - void changeEvent(QEvent *e); + void mousePressEvent(QMouseEvent * e) override; + void mouseMoveEvent(QMouseEvent * e) override; + void resizeEvent(QResizeEvent *) override; + void dragEnterEvent(QDragEnterEvent * e) override; + void dropEvent(QDropEvent * e) override; + void changeEvent(QEvent *e) override; QFrame * label; QWidget * back; QAction * a_copy, * a_paste, * a_mix; QPalette pal; QPoint pp; - QMenu menu; - QColorDialog::ColorDialogOptions options; + QMenu * menu; + int options; bool frame; - -private slots: - void clicked(); - void copy() {QApplication::clipboard()->setText(color().name());} - void paste() {QColor c(QApplication::clipboard()->text()); if (c.isValid()) setColor(c);} - void mix(); - -signals: - void colorChanged(QColor); - }; #endif // COLORBUTTON_H diff --git a/libs/widgets/ecombobox.cpp b/libs/widgets/ecombobox.cpp index cee4ce6..744f284 100644 --- a/libs/widgets/ecombobox.cpp +++ b/libs/widgets/ecombobox.cpp @@ -1,58 +1,72 @@ +#include "ecombobox.h" +#include "clineedit.h" +#include "qabstractitemview.h" +#include "qad_types.h" +#include "qwidget.h" #include #include #include -#include "ecombobox.h" -#include "qad_types.h" +#include +#include +#include -class QAD_WIDGETS_EXPORT EModel: public QStandardItemModel { +class EModel: public QStandardItemModel { public: - EModel(QObject * parent = 0): QStandardItemModel(parent) { + EModel(QObject * parent = nullptr): QStandardItemModel(parent) { #if QT_VERSION < 0x050000 setSupportedDragActions(Qt::MoveAction); #endif } protected: - virtual Qt::ItemFlags flags(const QModelIndex & index) const { + virtual Qt::ItemFlags flags(const QModelIndex & index) const override { Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; if (!index.isValid()) f |= Qt::ItemIsDropEnabled; return f; } #if QT_VERSION >= 0x050000 - Qt::DropActions supportedDragActions() const {return Qt::MoveAction;} - Qt::DropActions supportedDropActions() const {return Qt::MoveAction;} + Qt::DropActions supportedDragActions() const override {return Qt::MoveAction;} + Qt::DropActions supportedDropActions() const override {return Qt::MoveAction;} #endif }; -EComboBox::EComboBox(QWidget * parent): QComboBox(parent) { - setView(&iv); +EComboBox::EComboBox(QWidget * parent) + : QComboBox(parent) + , iv(new QTreeView(this)) + , header(new QWidget(this)) + , icon(new QLabel(this)) + , filter(new CLineEdit(this)) +{ + setView(iv); setModel(new EModel()); - iv.setTextElideMode(Qt::ElideMiddle); - iv.setRootIsDecorated(false); - iv.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - iv.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - iv.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); - iv.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - iv.setMinimumHeight(100); - icon.setPixmap(QPixmap(":/icons/edit-find.png")); - icon.setScaledContents(true); - icon.setFixedSize(preferredIconSize(1.2, this)); + iv->setTextElideMode(Qt::ElideMiddle); + iv->setRootIsDecorated(false); + iv->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + iv->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + iv->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); + iv->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + iv->setMinimumHeight(100); + icon->setPixmap(QPixmap(":/icons/edit-find.png")); + icon->setScaledContents(true); + icon->setFixedSize(preferredIconSize(1.2, this)); ifont = nfont = font(); ifont.setItalic(true); #if QT_VERSION >= 0x040700 - filter.setPlaceholderText(tr("Filter")); - filter.setFont(ifont); + filter->setPlaceholderText(tr("Filter")); + filter->setFont(ifont); #endif - header.setAutoFillBackground(true); - header.setLayout(new QBoxLayout(QBoxLayout::LeftToRight)); - header.layout()->setSpacing(2); - header.layout()->setContentsMargins(2, 0, 0, 0); - header.layout()->addWidget(&icon); - header.layout()->addWidget(&filter); - header.setParent(iv.header()); - connect(&filter, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); + header->setAutoFillBackground(true); + header->setLayout(new QBoxLayout(QBoxLayout::LeftToRight)); + header->layout()->setSpacing(2); + header->layout()->setContentsMargins(2, 0, 0, 0); + header->layout()->addWidget(icon); + header->layout()->addWidget(filter); + header->setParent(iv->header()); + connect(filter, &CLineEdit::textChanged, this, [this](const QString & text){ + EComboBox::filterChanged(text, false); + }); connect(model(), &EModel::layoutChanged, this, &EComboBox::rowsChanged); } @@ -65,12 +79,12 @@ QSize EComboBox::sizeHint() const { void EComboBox::showPopup() { - iv.setDragDropMode(isEditable() ? QAbstractItemView::InternalMove : QAbstractItemView::NoDragDrop); - filterChanged(filter.text(), true); + iv->setDragDropMode(isEditable() ? QAbstractItemView::InternalMove : QAbstractItemView::NoDragDrop); + filterChanged(filter->text(), true); QComboBox::showPopup(); - QRect r = iv.header()->rect(); - header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1); - filter.setFocus(); + QRect r = iv->header()->rect(); + header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1); + filter->setFocus(); } @@ -79,7 +93,7 @@ void EComboBox::changeEvent(QEvent * e) { switch (e->type()) { case QEvent::LanguageChange: #if QT_VERSION >= 0x040700 - filter.setPlaceholderText(tr("Filter")); + filter->setPlaceholderText(tr("Filter")); #endif break; default: @@ -89,36 +103,40 @@ void EComboBox::changeEvent(QEvent * e) { void EComboBox::filterChanged(const QString & text, bool first) { - if (filter.text().isEmpty()) filter.setFont(ifont); - else filter.setFont(nfont); - iv.hide(); - QModelIndex pi = iv.rootIndex(); + if (filter->text().isEmpty()) { + filter->setFont(ifont); + } else { + filter->setFont(nfont); + } + iv->hide(); + QModelIndex pi = iv->rootIndex(); + int row_count = iv->model()->rowCount(); if (text.isEmpty()) { - for (int i = 0; i < iv.model()->rowCount(); ++i) { - iv.setRowHidden(i, pi, false); - iv.model()->setData(iv.model()->index(i, 0), iv.model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole); + for (int i = 0; i < row_count; ++i) { + iv->setRowHidden(i, pi, false); + iv->model()->setData(iv->model()->index(i, 0), iv->model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole); } - iv.show(); + iv->show(); if (first) return; hidePopup(); showPopup(); qApp->processEvents(); - QRect r = iv.header()->rect(); - header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1); + QRect r = iv->header()->rect(); + header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1); return; } - for (int i = 0; i < iv.model()->rowCount(); ++i) { - iv.setRowHidden(i, pi, !iv.model()->index(i, 0, pi).data().toString().contains( + for (int i = 0; i < row_count; ++i) { + iv->setRowHidden(i, pi, !iv->model()->index(i, 0, pi).data().toString().contains( #if QT_VERSION_MAJOR <= 5 QRegExp(text, Qt::CaseInsensitive) #else QRegularExpression(text, QRegularExpression::CaseInsensitiveOption) #endif )); - iv.model()->setData(iv.model()->index(i, 0), iv.model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole); + iv->model()->setData(iv->model()->index(i, 0), iv->model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole); } - iv.show(); + iv->show(); qApp->processEvents(); - QRect r = iv.header()->rect(); - header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1); + QRect r = iv->header()->rect(); + header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1); } diff --git a/libs/widgets/ecombobox.h b/libs/widgets/ecombobox.h index fd58ee1..c1333ba 100644 --- a/libs/widgets/ecombobox.h +++ b/libs/widgets/ecombobox.h @@ -20,39 +20,40 @@ #ifndef ECOMBOBOX_H #define ECOMBOBOX_H -#include -#include -#include -#include -#include "clineedit.h" #include "qad_widgets_export.h" +#include + + +class CLineEdit; +class QLabel; +class QTreeView; class QAD_WIDGETS_EXPORT EComboBox: public QComboBox { Q_OBJECT public: - explicit EComboBox(QWidget * parent = 0); + explicit EComboBox(QWidget * parent = nullptr); - QSize sizeHint() const; + QSize sizeHint() const override; public slots: - virtual void showPopup(); - -private: - void changeEvent(QEvent *e); + void showPopup() override; - QTreeView iv; - QWidget header; - QLabel icon; - CLineEdit filter; - QFont nfont, ifont; - private slots: - void filterChanged(const QString & text, bool first = false); - + void filterChanged(const QString & text, bool first); + signals: void rowsChanged(); + +private: + void changeEvent(QEvent *e) override; + + QTreeView * iv; + QWidget * header; + QLabel * icon; + CLineEdit * filter; + QFont nfont, ifont; }; #endif // ECOMBOBOX_H diff --git a/libs/widgets/evalspinbox.cpp b/libs/widgets/evalspinbox.cpp index 7a372c2..bb07f42 100644 --- a/libs/widgets/evalspinbox.cpp +++ b/libs/widgets/evalspinbox.cpp @@ -1,18 +1,19 @@ #include "evalspinbox.h" +#include "qad_types.h" +#include "qpievaluator_p.h" #include #include #include +#include +#include +#include +#include +#include #if QT_VERSION_MAJOR <= 5 # include #else # include #endif -#include -#include -#include -#include -#include "qad_types.h" -#include "qpievaluator_p.h" EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { @@ -21,7 +22,6 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { label = new QLabel(lineEdit()); eval = new QPIEvaluator(); precision_ = -1; -// label->hide(); clear_im.load(":/icons/edit-clear-locationbar-rtl.png"); icon_ok.load(":/icons/dialog-ok-apply.png"); icon_fail.load(":/icons/dialog-warning.png"); @@ -35,14 +35,11 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) { cw->hide(); cw_visible = false; calc_visible = true; - //lineEdit()->setStyleSheet("color: darkgreen;"); - //lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10)); cw->installEventFilter(this); status->installEventFilter(this); connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString))); - connect(this, SIGNAL(editingFinished()), this, SLOT(setExpression_())); + connect(this, SIGNAL(editingFinished()), this, SLOT(setExpressionSlot())); label->setText("0"); - //connect(cw, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(clearMouseRelease(QMouseEvent * ))); } @@ -57,11 +54,17 @@ EvalSpinBox::~EvalSpinBox() { bool EvalSpinBox::eventFilter(QObject * o, QEvent * e) { switch (e->type()) { case QEvent::MouseButtonRelease: - if (o == cw) clearMouseRelease((QMouseEvent * )e); + if (o == cw) { + clearMouseRelease(static_cast(e)); + } break; case QEvent::Paint: - if (o == status) statusPaintEvent(); - if (o == cw) cwPaintEvent(); + if (o == status) { + statusPaintEvent(); + } + if (o == cw) { + cwPaintEvent(); + } break; default : break; } @@ -141,8 +144,9 @@ void EvalSpinBox::textChanged_(const QString & text) { icon = icon_ok; status->setToolTip("OK -> "+QString::number(value(), 'G', 10)); } -// qDebug() << "value =" << value(); - if (pv != value()) emit valueChanged(value()); + if (pv != value()) { + emit valueChanged(value()); + } } else { icon = icon_fail; status->setToolTip(eval->error()); @@ -151,7 +155,7 @@ void EvalSpinBox::textChanged_(const QString & text) { } -void EvalSpinBox::setExpression_() { +void EvalSpinBox::setExpressionSlot() { bool td = false; double pv = value(); QString t = text(); @@ -160,8 +164,7 @@ void EvalSpinBox::setExpression_() { t.chop(1); } if (eval->check(t)) { - /*if (eval.expression() == "0") lineEdit()->clear(); - else*/ lineEdit()->setText(eval->expression()); + lineEdit()->setText(eval->expression()); eval->evaluate(); if (td) lineEdit()->setText(QString::number(value(), 'G', precision_ > 0 ? precision_ : 16)); status->setToolTip("OK -> " + QString::number(value(), 'G', 10)); @@ -169,13 +172,8 @@ void EvalSpinBox::setExpression_() { } else { icon = icon_fail; status->setToolTip(eval->error()); -// qDebug() << eval.expression(); } if (!label->isHidden()) { -// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect()) -// label->setText("

" + eval.expression() + " -> " + QString::number(value(), 'G', 10) + "

"); -// else -// label->setText(eval.expression()); if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect()) label->setText("

-> " + QString::number(value(), 'G', 10) + "

"); else @@ -188,29 +186,24 @@ void EvalSpinBox::setExpression_() { lineEdit()->setStyleSheet(""); status->hide(); } - // lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10)); - //lineEdit()->setText(""); lineEdit()->blockSignals(false); } -// qDebug() << "value =" << value(); if (pv != value()) emit valueChanged(value()); } void EvalSpinBox::setExpression(const QString & expr) { lineEdit()->setText(expr); - //if (eval.expression() == "0") lineEdit()->clear(); cw->setVisible(text() != dt && cw_visible); - setExpression_(); + setExpressionSlot(); } void EvalSpinBox::setValue(double val) { lineEdit()->setText(QString::number(val, 'G', precision_ > 0 ? precision_ : 16)); - //if (val == 0) lineEdit()->clear(); cw->setVisible(text() != dt && cw_visible); - setExpression_(); + setExpressionSlot(); } @@ -221,7 +214,7 @@ void EvalSpinBox::stepBy(int steps) { void EvalSpinBox::clear() { lineEdit()->setText(dt); - setExpression_(); + setExpressionSlot(); cw->hide(); resizeIcons(); emit cleared(); @@ -259,7 +252,6 @@ QAbstractSpinBox::StepEnabled EvalSpinBox::stepEnabled() const { void EvalSpinBox::focusInEvent(QFocusEvent * event) { -// qDebug() << "focus_in"; label->hide(); status->show(); lineEdit()->blockSignals(true); @@ -273,29 +265,24 @@ void EvalSpinBox::focusInEvent(QFocusEvent * event) { void EvalSpinBox::focusOutEvent(QFocusEvent * event) { QAbstractSpinBox::focusOutEvent(event); -// qDebug() << eval.expression() << QString::number(value(), 'G', 10); -// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect()) -// label->setText("

" + eval.expression() + " -> " + QString::number(value(), 'G', 10) + "

"); -// else -// label->setText(eval.expression()); - if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect()) + if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect()) { label->setText("

-> " + QString::number(value(), 'G', 10) + "

"); - else + } else { label->setText(""); - if (calc_visible) + } + if (calc_visible) { label->show(); + } lineEdit()->blockSignals(true); if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;"); else status->hide(); -// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10)); - //lineEdit()->clear(); lineEdit()->blockSignals(false); resizeIcons(); } void EvalSpinBox::wheelEvent(QWheelEvent * event) { - if (event->modifiers().testFlag(Qt::ShiftModifier)) + if (event->modifiers().testFlag(Qt::ShiftModifier)) { stepByDouble( #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) event->delta() @@ -303,13 +290,13 @@ void EvalSpinBox::wheelEvent(QWheelEvent * event) { event->angleDelta().y() #endif > 0 ? 0.1 : -0.1); - else + } else { QAbstractSpinBox::wheelEvent(event); + } } void EvalSpinBox::stepByDouble(double steps) { - //qDebug() << "step" << steps; if (isReadOnly()) return; QString t = text(); if (eval->check(t)) { @@ -347,13 +334,7 @@ void EvalSpinBox::stepByDouble(double steps) { void EvalSpinBox::setDefaultText(const QString & t) { -// bool def = (!cw->isHidden()); dt = t; -// if (def) { -// lineEdit()->setText(dt); -// setExpression_(); -// } - //if (t == eval.expression() || (value() == 0 && t.isEmpty())) clear(); cw->setVisible((eval->expression() != dt || (dt.isEmpty() && eval->expression() == "0")) && cw_visible); resizeIcons(); } @@ -368,7 +349,8 @@ void EvalSpinBox::setClearButtonVisible(bool visible) { void EvalSpinBox::setCalculationVisible(bool visible) { calc_visible = visible; - setExpression_(); - if (!calc_visible) + setExpressionSlot(); + if (!calc_visible) { label->hide(); + } } diff --git a/libs/widgets/evalspinbox.h b/libs/widgets/evalspinbox.h index bcd2271..de62b4f 100644 --- a/libs/widgets/evalspinbox.h +++ b/libs/widgets/evalspinbox.h @@ -20,15 +20,14 @@ #ifndef EVALSPINBOX_H #define EVALSPINBOX_H -#include -#include #include "qad_widgets_export.h" +#include + class QPIEvaluator; - - class QLabel; + class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox { Q_OBJECT @@ -40,8 +39,8 @@ class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox Q_PROPERTY(int precision READ precision WRITE setPrecision) public: - explicit EvalSpinBox(QWidget * parent = 0); - ~EvalSpinBox(); + explicit EvalSpinBox(QWidget * parent = nullptr); + ~EvalSpinBox() override; double value() const; const QString & expression() const; @@ -51,20 +50,45 @@ public: bool isCleared() const; int precision() const {return precision_;} - virtual void stepBy(int steps); - virtual void clear(); - virtual QSize sizeHint() const; + void stepBy(int steps) override; + void clear() override; + QSize sizeHint() const override; + +public slots: + void setExpression(const QString & expr); + void setValue(double val); + void setDefaultText(const QString & t); + void setClearButtonVisible(bool visible); + void setCalculationVisible(bool visible); + void setPrecision(int precision) {precision_ = precision;} protected: QString text() const {return QAbstractSpinBox::text();} - virtual StepEnabled stepEnabled() const; - virtual void focusInEvent(QFocusEvent *event); - virtual void focusOutEvent(QFocusEvent *event); - virtual void wheelEvent(QWheelEvent *event); + StepEnabled stepEnabled() const override; + void focusInEvent(QFocusEvent *event) override; + void focusOutEvent(QFocusEvent *event) override; + void wheelEvent(QWheelEvent *event) override; void stepByDouble(double steps); +private slots: + void clearMouseRelease(QMouseEvent * e); + void textChanged_(const QString & text); + void setExpressionSlot(); + void resizeIcons(); + +signals: + void valueChanged(double val); + void cleared(); + +private: + bool eventFilter(QObject * o, QEvent * e) override; + void resizeEvent(QResizeEvent * ) override; + void changeEvent(QEvent * e) override; + void statusPaintEvent(); + void cwPaintEvent(); + QWidget * status; QWidget * cw; QPIEvaluator * eval; @@ -77,32 +101,6 @@ protected: QString dt; bool cw_visible, calc_visible; int precision_; - -private: - bool eventFilter(QObject * o, QEvent * e); - void resizeEvent(QResizeEvent * ); - void changeEvent(QEvent * e); - void statusPaintEvent(); - void cwPaintEvent(); - -private slots: - void clearMouseRelease(QMouseEvent * e); - void textChanged_(const QString & text); - void setExpression_(); - void resizeIcons(); - -public slots: - void setExpression(const QString & expr); - void setValue(double val); - void setDefaultText(const QString & t); - void setClearButtonVisible(bool visible); - void setCalculationVisible(bool visible); - void setPrecision(int precision) {precision_ = precision;} - -signals: - void valueChanged(double val); - void cleared(); - }; #endif // EVALSPINBOX_H diff --git a/libs/widgets/iconedlabel.cpp b/libs/widgets/iconedlabel.cpp index 40bc52d..2606088 100644 --- a/libs/widgets/iconedlabel.cpp +++ b/libs/widgets/iconedlabel.cpp @@ -30,8 +30,9 @@ QIcon IconedLabel::icon() const { bool IconedLabel::event(QEvent * e) { - if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) + if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) { setIconSize(iconSize()); + } return QFrame::event(e); } @@ -43,9 +44,10 @@ void IconedLabel::checkSpacing() { layout()->setSpacing(0); } else { QStyle * s = style(); - if (s) + if (s) { layout()->setSpacing(s->layoutSpacing(QSizePolicy::Label, QSizePolicy::Label, dir_ <= Direction::RightToLeft ? Qt::Horizontal : Qt::Vertical)); + } } } @@ -79,9 +81,10 @@ void IconedLabel::setIconSize(const QSize & s) { void IconedLabel::setDirection(IconedLabel::Direction d) { dir_ = d; - if (layout() != 0) + if (layout()) { delete layout(); - QLayout * lay = new QBoxLayout((QBoxLayout::Direction)dir_); + } + QLayout * lay = new QBoxLayout(static_cast(dir_)); lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding)); lay->addWidget(&label_); lay->addWidget(&icon_); diff --git a/libs/widgets/iconedlabel.h b/libs/widgets/iconedlabel.h index 3572e66..8ea5952 100644 --- a/libs/widgets/iconedlabel.h +++ b/libs/widgets/iconedlabel.h @@ -20,10 +20,9 @@ #ifndef ICONEDLABEL_H #define ICONEDLABEL_H +#include "qad_widgets_export.h" #include #include -#include "qad_types.h" -#include "qad_widgets_export.h" class QAD_WIDGETS_EXPORT IconedLabel: public QFrame @@ -37,7 +36,7 @@ class QAD_WIDGETS_EXPORT IconedLabel: public QFrame public: enum Direction {LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop = 3}; - explicit IconedLabel(QWidget * parent = 0); + explicit IconedLabel(QWidget * parent = nullptr); QString text() const; QIcon icon() const; @@ -46,8 +45,14 @@ public: QLabel * textLabel() {return &label_;} +public slots: + void setText(const QString & t); + void setIcon(const QIcon & i); + void setIconSize(const QSize & s); + void setDirection(Direction d); + protected: - virtual bool event(QEvent * e); + bool event(QEvent * e) override; void checkSpacing(); QSize realIconSize() const; @@ -55,15 +60,6 @@ protected: QIcon sicon_; QSize size_; Direction dir_; - -public slots: - void setText(const QString & t); - void setIcon(const QIcon & i); - void setIconSize(const QSize & s); - void setDirection(Direction d); - -signals: - }; #endif // ICONEDLABEL_H diff --git a/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp index b0f8654..b9e131e 100644 --- a/libs/widgets/image_view.cpp +++ b/libs/widgets/image_view.cpp @@ -1,4 +1,5 @@ #include "image_view.h" +#include #include #include #include @@ -9,7 +10,7 @@ #include -ImageView::ImageView(QWidget * parent): QGraphicsView(parent) { +ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphicsPixmapItem) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setDragMode(QGraphicsView::NoDrag); @@ -17,9 +18,9 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) { setScene(new QGraphicsScene()); setRenderHint(QPainter::Antialiasing, true); setRenderHint(QPainter::SmoothPixmapTransform, true); - item.setTransformationMode(Qt::SmoothTransformation); - item.setFlags(QGraphicsItem::GraphicsItemFlags()); - scene()->addItem(&item); + item->setTransformationMode(Qt::SmoothTransformation); + item->setFlags(QGraphicsItem::GraphicsItemFlags()); + scene()->addItem(item); viewport()->setAutoFillBackground(false); viewport()->installEventFilter(this); autofit_ = true; @@ -28,6 +29,7 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) { ImageView::~ImageView() { + delete item; } @@ -50,7 +52,7 @@ void ImageView::setViewInteractive(bool yes) { void ImageView::setImage(const QImage & i, bool save) { im_data.clear(); if (i.isNull()) { - item.setPixmap(QPixmap()); + item->setPixmap(QPixmap()); map = QPixmap(); return; } @@ -67,7 +69,7 @@ void ImageView::setImage(const QImage & i, bool save) { void ImageView::setImage(const QByteArray & i) { im_data = i; if (i.isEmpty()) { - item.setPixmap(QPixmap()); + item->setPixmap(QPixmap()); map = QPixmap(); return; } @@ -78,7 +80,7 @@ void ImageView::setImage(const QByteArray & i) { void ImageView::clear() { im_data.clear(); - item.setPixmap(QPixmap()); + item->setPixmap(QPixmap()); map = QPixmap(); } @@ -103,7 +105,7 @@ void ImageView::wheelEvent(QWheelEvent * e) { bool ImageView::eventFilter(QObject * o, QEvent * e) { - QMouseEvent * me = (QMouseEvent *)e; + QMouseEvent * me = reinterpret_cast(e); switch (e->type()) { case QEvent::Resize: adjustView(); @@ -137,23 +139,22 @@ void ImageView::adjustView() { ws *= devicePixelRatio(); #endif int nw = map.size().boundedTo(ws).width(); - item.setScale(1.); + item->setScale(1.); if (nw > 0) { qreal mp = map.width() / nw; if (mp > 1.) { QSize ss = map.size(); - item.setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); - item.setScale(double(ss.width()) / item.pixmap().width()); + item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + item->setScale(double(ss.width()) / item->pixmap().width()); } else - item.setPixmap(map); + item->setPixmap(map); } else - item.setPixmap(map); + item->setPixmap(map); if (!autofit_) return; - QRectF r = item.mapRectToScene(item.boundingRect()); + QRectF r = item->mapRectToScene(item->boundingRect()); setSceneRect(r); fitInView(r, Qt::KeepAspectRatio); centerOn(r.center()); - } diff --git a/libs/widgets/image_view.h b/libs/widgets/image_view.h index 1a71067..02386c0 100644 --- a/libs/widgets/image_view.h +++ b/libs/widgets/image_view.h @@ -20,9 +20,11 @@ #ifndef IMAGE_VIEW_H #define IMAGE_VIEW_H -#include -#include #include "qad_widgets_export.h" +#include + + +class QGraphicsPixmapItem; class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView @@ -31,31 +33,16 @@ class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive) public: - ImageView(QWidget * parent = 0); - ~ImageView(); + ImageView(QWidget * parent = nullptr); + ~ImageView() override; void setImage(const QImage & i, bool save = true); void setImage(const QByteArray & i); QByteArray image() const {return im_data;} QPixmap pixmap() const; bool viewInteractive() const {return interactive_;} - void clear(); -private: - void mouseDoubleClickEvent(QMouseEvent * e); - void mousePressEvent(QMouseEvent * e); - void wheelEvent(QWheelEvent * e); - bool eventFilter(QObject * o, QEvent * e); - void adjustView(); - - QGraphicsPixmapItem item; - QByteArray im_data; - QPoint prev_pos; - bool autofit_, interactive_; - QPixmap map; - - public slots: void autofit(); void setPixmap(QPixmap pixmap); @@ -64,6 +51,18 @@ public slots: signals: void clicked(QPointF, Qt::MouseButtons); +private: + void mouseDoubleClickEvent(QMouseEvent * e) override; + void mousePressEvent(QMouseEvent * e) override; + void wheelEvent(QWheelEvent * e) override; + bool eventFilter(QObject * o, QEvent * e) override; + void adjustView(); + + QGraphicsPixmapItem * item; + QByteArray im_data; + QPoint prev_pos; + bool autofit_, interactive_; + QPixmap map; }; #endif // IMAGE_VIEW_H diff --git a/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp index c762e90..a5dd496 100644 --- a/libs/widgets/qcodeedit.cpp +++ b/libs/widgets/qcodeedit.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) # include #endif @@ -24,7 +26,7 @@ Q_DECLARE_METATYPE(QCodeEdit::ACEntry) class _QCE_Viewport: public QWidget { public: - _QCE_Viewport(QWidget * p = 0): QWidget(p) { + _QCE_Viewport(QWidget * p = nullptr): QWidget(p) { setObjectName("__qcodeedit_viewport__"); setMouseTracking(true); //setCursor(Qt::IBeamCursor); diff --git a/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h index ec83c71..00341ea 100644 --- a/libs/widgets/qcodeedit.h +++ b/libs/widgets/qcodeedit.h @@ -49,7 +49,7 @@ class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget friend class _QCE_Viewport; public: - QCodeEdit(QWidget * parent = 0); + QCodeEdit(QWidget * parent = nullptr); ~QCodeEdit(); enum ACClassType { @@ -177,7 +177,7 @@ private: bool hasBlockSelection() const; void startBlockSelection(); void cancelBlockSelection(); - void switchBlockSelection(QKeyEvent * ke = 0); + void switchBlockSelection(QKeyEvent * ke = nullptr); bool removeBlockSelection(bool is_del); void insertBlockSelection(QString text); void createBlockSelection(); diff --git a/libs/widgets/qcodeedit_completer_p.cpp b/libs/widgets/qcodeedit_completer_p.cpp index 066aae4..431e28f 100644 --- a/libs/widgets/qcodeedit_completer_p.cpp +++ b/libs/widgets/qcodeedit_completer_p.cpp @@ -1,4 +1,5 @@ #include "qcodeedit_completer_p.h" +#include "qad_types.h" #include diff --git a/libs/widgets/shortcuts.cpp b/libs/widgets/shortcuts.cpp index ccb4ece..6b96141 100644 --- a/libs/widgets/shortcuts.cpp +++ b/libs/widgets/shortcuts.cpp @@ -1,4 +1,23 @@ #include "shortcuts.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/// ShortcutEdit + +ShortcutEdit::ShortcutEdit(QWidget *parent) : CLineEdit(parent) { + ti = nullptr; + ca = nullptr; + connect(this, &CLineEdit::textChanged, this, &ShortcutEdit::textChangedSlot); +} void ShortcutEdit::keyPressEvent(QKeyEvent * e) { @@ -6,14 +25,56 @@ void ShortcutEdit::keyPressEvent(QKeyEvent * e) { km &= ~Qt::KeypadModifier; km &= ~Qt::GroupSwitchModifier; if (e->key() != Qt::Key_Control && e->key() != Qt::Key_Shift && - e->key() != Qt::Key_Alt && e->key() != Qt::Key_Meta) - setText(QKeySequence(km | e->key()).toString()); + e->key() != Qt::Key_Alt && e->key() != Qt::Key_Meta) { + setText(QKeySequence(km | e->key()).toString()); + } } +void ShortcutEdit::assignAction(QAction *a) { + clear(); + ca = a; + reset(); +} + + +QAction *ShortcutEdit::action() const { + return ca; +} + + +bool ShortcutEdit::isEmpty() const { + return text().isEmpty(); +} + + +void ShortcutEdit::commit() { + if (!ca) { + return; + } + ca->setShortcut(QKeySequence(text())); +} + + +void ShortcutEdit::reset() { + if (!ca) { + return; + } + setText(ca->shortcut().toString()); +} + + +void ShortcutEdit::textChangedSlot(QString t) { + if (ti) { + ti->setText(1, t); + } +} + + +/// Shortcuts Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) { - aw = 0; + aw = nullptr; QImage ti(QSize(16, 16), QImage::Format_ARGB32_Premultiplied); QPainter p(&ti); p.setCompositionMode(QPainter::CompositionMode_Clear); @@ -42,8 +103,9 @@ Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) { Shortcuts::~Shortcuts() { - foreach (ShortcutEdit * i, edits) + for (ShortcutEdit * i : edits) { delete i; + } edits.clear(); } @@ -60,9 +122,12 @@ void Shortcuts::changeEvent(QEvent * e) { void Shortcuts::assignWindow(QWidget * w) { - if (w == 0) return; - while ((qobject_cast(w) == 0) && (w->parentWidget() != 0)) + if (!w) { + return; + } + while (!(qobject_cast(w)) && (w->parentWidget())) { w = w->parentWidget(); + } aw = qobject_cast(w); updateShortcuts(); } @@ -71,30 +136,38 @@ void Shortcuts::assignWindow(QWidget * w) { QStringList Shortcuts::actionTree(QAction * a) { QStringList tree; QList aw = a->associatedWidgets(); - if (aw.size() == 0) return tree; - QWidget * cw = 0; - QMenu * tm; - QToolBar * tt; - foreach (QWidget * i, aw) { - tm = qobject_cast(i); - if (tm == 0) continue; - cw = i; - while (cw != 0) { - tm = qobject_cast(cw); - if (tm != 0) { - if (!tm->title().isEmpty()) - tree.push_front(tm->title()); - cw = cw->parentWidget(); - } else break; - } - if (!tree.isEmpty()) return tree; + if (aw.size() == 0) { + return tree; } - foreach (QWidget * i, aw) { - tt = qobject_cast(i); - if (tt == 0) continue; - cw = i; - if (!tt->windowTitle().isEmpty()) + for (QWidget * i : aw) { + auto tm = qobject_cast(i); + if (!tm) { + continue; + } + auto cw = i; + while (cw) { + tm = qobject_cast(cw); + if (tm) { + if (!tm->title().isEmpty()) { + tree.push_front(tm->title()); + } + cw = cw->parentWidget(); + } else { + break; + } + } + if (!tree.isEmpty()) { + return tree; + } + } + for (QWidget * i : aw) { + auto tt = qobject_cast(i); + if (!tt) { + continue; + } + if (!tt->windowTitle().isEmpty()) { tree.push_front(tt->windowTitle()); + } break; } return tree; @@ -103,8 +176,10 @@ QStringList Shortcuts::actionTree(QAction * a) { QList > Shortcuts::shortcuts() { QList > l; - foreach (ShortcutEdit * i, edits) { - if (i->action()->objectName().isEmpty()) continue; + for (const ShortcutEdit * i : edits) { + if (i->action()->objectName().isEmpty()) { + continue; + } l << QPair(i->action()->objectName(), i->text()); } return l; @@ -124,19 +199,26 @@ void Shortcuts::clear() { bool Shortcuts::checkAction(QAction * a) { - if (a->menu() != 0) return false; - if (a->isSeparator()) return false; - if (a->text().isEmpty()) return false; - if (a->associatedWidgets().isEmpty()) return false; - if (QString(a->metaObject()->className()) != "QAction") return false; - if (qobject_cast(a) != 0) return false; + if (a->menu() || a->isSeparator() || a->text().isEmpty()) { + return false; + } + if (a->associatedWidgets().isEmpty()) { + return false; + } + if (QString(a->metaObject()->className()) != "QAction") { + return false; + } + if (qobject_cast(a)) { + return false; + } return true; } void Shortcuts::updateShortcuts() { - //return; - if (aw == 0 || !active) return; + if (!aw || !active) { + return; + } hide(); int cpos = verticalScrollBar()->value(); clear(); @@ -150,12 +232,12 @@ void Shortcuts::updateShortcuts() { QStringList tree; bool s = isSortingEnabled(), isFound; setSortingEnabled(false); - foreach (QAction * i, al) { + for (QAction * i : al) { if (!checkAction(i)) continue; edits.push_back(new ShortcutEdit()); tree = actionTree(i); pi = invisibleRootItem(); - foreach (QString t, tree) { + for (const QString & t : tree) { isFound = false; for (int j = 0; j < pi->childCount(); ++j) { if (pi->child(j)->text(0) == t) { @@ -198,38 +280,55 @@ void Shortcuts::updateShortcuts() { void Shortcuts::commit() { - foreach (ShortcutEdit * i, edits) + for (ShortcutEdit * i : edits) { i->commit(); + } } -void Shortcuts::reset() { - foreach (ShortcutEdit * i, edits) +void Shortcuts::resetShortcuts() { + for (ShortcutEdit * i : edits) { i->reset(); + } updateShortcuts(); } void Shortcuts::filter(const QString & what) { hide(); - for (int i = 0; i < topLevelItemCount(); ++i) + for (int i = 0; i < topLevelItemCount(); ++i) { filterTree(topLevelItem(i), what); + } show(); } bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) { if (f.isEmpty()) { - for (int i = 0; i < ti->childCount(); ++i) + for (int i = 0; i < ti->childCount(); ++i) { filterTree(ti->child(i), f); + } ti->setHidden(false); return true; } bool isFound = false; - for (int i = 0; i < ti->childCount(); ++i) - if (filterTree(ti->child(i), f)) isFound = true; + for (int i = 0; i < ti->childCount(); ++i) { + if (filterTree(ti->child(i), f)) { + isFound = true; + } + } if (ti->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0 || - ti->text(1).indexOf(f, 0, Qt::CaseInsensitive) >= 0) isFound = true; + ti->text(1).indexOf(f, 0, Qt::CaseInsensitive) >= 0) { + isFound = true; + } ti->setHidden(!isFound); return isFound; } + + +void Shortcuts::updateEditorGeometries() { + for (ShortcutEdit * i : edits) { + i->setGeometry(visualRect(indexFromItem(i->ti, 1))); + } +} + diff --git a/libs/widgets/shortcuts.h b/libs/widgets/shortcuts.h index 2bdc1f8..d07a295 100644 --- a/libs/widgets/shortcuts.h +++ b/libs/widgets/shortcuts.h @@ -20,20 +20,13 @@ #ifndef SHORTCUTS_H #define SHORTCUTS_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "clineedit.h" #include "qad_widgets_export.h" +#include "clineedit.h" +#include + + +class QMainWindow; +class ShortcutEdit; class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit @@ -41,63 +34,55 @@ class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit Q_OBJECT friend class Shortcuts; public: - explicit ShortcutEdit(QWidget * parent = 0): CLineEdit(parent) {ti = 0; ca = 0; connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));} + explicit ShortcutEdit(QWidget *parent = nullptr); - void assignAction(QAction * a) {clear(); ca = a; reset();} - QAction * action() const {return ca;} - bool isEmpty() const {return text().isEmpty();} - void commit() {if (ca == 0) return; ca->setShortcut(QKeySequence(text()));} - void reset() {if (ca == 0) return; setText(ca->shortcut().toString());} + void assignAction(QAction *a); + QAction *action() const; + bool isEmpty() const; + void commit(); + void reset(); private slots: - void textChanged_(QString t) {if (ti != 0) ti->setText(1, t);} + void textChangedSlot(QString t); private: - void keyPressEvent(QKeyEvent * e); + void keyPressEvent(QKeyEvent * e) override; QAction * ca; QTreeWidgetItem * ti; - }; class QAD_WIDGETS_EXPORT Shortcuts: public QTreeWidget { Q_OBJECT - public: - explicit Shortcuts(QWidget * parent = 0, bool on = true); - ~Shortcuts(); + explicit Shortcuts(QWidget * parent = nullptr, bool on = true); + ~Shortcuts() override; void assignWindow(QWidget * w); void setActive(bool on) {active = on;} - QList > shortcuts(); QStringList actionTree(QAction * a); static bool checkAction(QAction * a); + QList > shortcuts(); public slots: void clear(); void updateShortcuts(); void commit(); - void reset(); + void resetShortcuts(); void filter(const QString & what); private: - virtual void updateEditorGeometries() {foreach (ShortcutEdit * i, edits) i->setGeometry(visualRect(indexFromItem(i->ti, 1)));} - virtual void changeEvent(QEvent * ); - bool filterTree(QTreeWidgetItem * ti, QString f); + virtual void updateEditorGeometries() override; + virtual void changeEvent(QEvent *) override; + bool filterTree(QTreeWidgetItem *ti, QString f); QMainWindow * aw; - QVector edits; + QVector edits; QIcon empty_icon; QFont bfont; bool active; - -private slots: - -signals: - void shortcutChanged(QAction * , QShortcut & ); - }; #endif // SPINSLIDER_H