refactoring qad widgets part 1
c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
||||||
project(QAD)
|
project(QAD)
|
||||||
set(QAD_MAJOR 2)
|
set(QAD_MAJOR 2)
|
||||||
set(QAD_MINOR 10)
|
set(QAD_MINOR 11)
|
||||||
set(QAD_REVISION 0)
|
set(QAD_REVISION 0)
|
||||||
set(QAD_SUFFIX )
|
set(QAD_SUFFIX )
|
||||||
set(QAD_COMPANY SHS)
|
set(QAD_COMPANY SHS)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDebug>
|
#include <QClipboard>
|
||||||
|
|
||||||
|
|
||||||
_DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
_DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "propertyeditor.h"
|
#include "propertyeditor.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
|
||||||
QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const {
|
QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ void CharDialog::resizeEvent(QResizeEvent * ) {
|
|||||||
ui->tableChars->setColumnCount(c);
|
ui->tableChars->setColumnCount(c);
|
||||||
for (int i = 0; i < r; ++i) {
|
for (int i = 0; i < r; ++i) {
|
||||||
for (int j = 0; j < c; ++j) {
|
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->setItem(i, j, new QTableWidgetItem());
|
||||||
ui->tableChars->item(i, j)->setTextAlignment(Qt::AlignCenter);
|
ui->tableChars->item(i, j)->setTextAlignment(Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ void CharDialog::on_spinSize_valueChanged(int index) {
|
|||||||
QFont font = ui->tableChars->font();
|
QFont font = ui->tableChars->font();
|
||||||
font.setPointSize(size);
|
font.setPointSize(size);
|
||||||
ui->tableChars->setFont(font);
|
ui->tableChars->setFont(font);
|
||||||
resizeEvent(0);
|
resizeEvent(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,8 @@
|
|||||||
#ifndef CHARDIALOG_H
|
#ifndef CHARDIALOG_H
|
||||||
#define CHARDIALOG_H
|
#define CHARDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QMetaEnum>
|
|
||||||
#include <QDebug>
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -35,26 +33,12 @@ class QAD_WIDGETS_EXPORT CharDialog: public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CharDialog(QWidget * parent = 0);
|
explicit CharDialog(QWidget * parent = nullptr);
|
||||||
~CharDialog();
|
~CharDialog() override;
|
||||||
|
|
||||||
QChar selectedChar() {return sel_char;}
|
QChar selectedChar() {return sel_char;}
|
||||||
void setCharFont(const QFont & f);
|
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<QVector<QChar> > chars;
|
|
||||||
QVector<QChar> * cur;
|
|
||||||
QChar sel_char;
|
|
||||||
int size, csize;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_comboCategory_currentIndexChanged(int index);
|
void on_comboCategory_currentIndexChanged(int index);
|
||||||
void on_verticalScroll_valueChanged(int index);
|
void on_verticalScroll_valueChanged(int index);
|
||||||
@@ -67,6 +51,17 @@ private slots:
|
|||||||
signals:
|
signals:
|
||||||
void charSelected(QChar ch);
|
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<QVector<QChar> > chars;
|
||||||
|
QVector<QChar> * cur;
|
||||||
|
QChar sel_char;
|
||||||
|
int size, csize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHARDIALOG_H
|
#endif // CHARDIALOG_H
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "clineedit.h"
|
#include "clineedit.h"
|
||||||
#include "qad_types.h"
|
#include "qad_types.h"
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
|
||||||
CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
||||||
@@ -9,7 +11,7 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
|||||||
cw->setToolTip(tr("Clear"));
|
cw->setToolTip(tr("Clear"));
|
||||||
cw->hide();
|
cw->hide();
|
||||||
cw->installEventFilter(this);
|
cw->installEventFilter(this);
|
||||||
connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
|
connect(this, &QLineEdit::textChanged, this, &CLineEdit::textChangedSlot);
|
||||||
int is = fontHeight(this);
|
int is = fontHeight(this);
|
||||||
QMargins m = textMargins();
|
QMargins m = textMargins();
|
||||||
m.setRight(m.right() + (is * 1.2));
|
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) {
|
bool CLineEdit::eventFilter(QObject * o, QEvent * e) {
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
clearMouseRelease((QMouseEvent * )e);
|
clearMouseRelease(static_cast<QMouseEvent *>(e));
|
||||||
break;
|
break;
|
||||||
case QEvent::Paint:
|
case QEvent::Paint:
|
||||||
cwPaintEvent();
|
cwPaintEvent();
|
||||||
@@ -62,5 +69,17 @@ void CLineEdit::setDefaultText(const QString & t, bool set_text) {
|
|||||||
cw->hide();
|
cw->hide();
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,39 +20,20 @@
|
|||||||
#ifndef CLINEEDIT_H
|
#ifndef CLINEEDIT_H
|
||||||
#define CLINEEDIT_H
|
#define CLINEEDIT_H
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT CLineEdit: public QLineEdit
|
class QAD_WIDGETS_EXPORT CLineEdit: public QLineEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
|
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CLineEdit(QWidget * parent = 0);
|
explicit CLineEdit(QWidget * parent = nullptr);
|
||||||
~CLineEdit() {delete cw;}
|
~CLineEdit() override;
|
||||||
|
|
||||||
const QString & defaultText() const {return dt;}
|
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:
|
public slots:
|
||||||
void clearClick() {if (!isEnabled()) return; setText(dt); emit cleared(); emit textEdited(dt);}
|
void clearClick() {if (!isEnabled()) return; setText(dt); emit cleared(); emit textEdited(dt);}
|
||||||
void setDefaultText(const QString & t, bool set_text = false);
|
void setDefaultText(const QString & t, bool set_text = false);
|
||||||
@@ -60,6 +41,19 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void cleared();
|
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
|
#endif // CLINEEDIT_H
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
#include "colorbutton.h"
|
#include "colorbutton.h"
|
||||||
#include <QDebug>
|
#include "qclipboard.h"
|
||||||
|
#include "qcolor.h"
|
||||||
|
#include "qmenu.h"
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <QMouseEvent>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
ColorButton::ColorButton(QWidget * parent): QPushButton(parent) {
|
|
||||||
|
ColorButton::ColorButton(QWidget * parent): QPushButton(parent), menu(new QMenu(this)) {
|
||||||
frame = false;
|
frame = false;
|
||||||
options = QColorDialog::ShowAlphaChannel;
|
options = QColorDialog::ShowAlphaChannel;
|
||||||
back = new QWidget(this);
|
back = new QWidget(this);
|
||||||
@@ -17,10 +24,10 @@ ColorButton::ColorButton(QWidget * parent): QPushButton(parent) {
|
|||||||
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
||||||
label->show();
|
label->show();
|
||||||
pal = label->palette();
|
pal = label->palette();
|
||||||
a_copy = menu.addAction(QIcon(":/icons/edit-copy.png"), tr("Copy"), this, SLOT(copy()));
|
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()));
|
a_paste = menu->addAction(QIcon(":/icons/edit-paste.png"), tr("Paste"), this, SLOT(paste()));
|
||||||
menu.addSeparator();
|
menu->addSeparator();
|
||||||
a_mix = menu.addAction(tr("Mix with clipboard"), this, SLOT(mix()));
|
a_mix = menu->addAction(tr("Mix with clipboard"), this, SLOT(mix()));
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
connect(this, SIGNAL(clicked(bool)), this, SLOT(clicked()));
|
connect(this, SIGNAL(clicked(bool)), this, SLOT(clicked()));
|
||||||
}
|
}
|
||||||
@@ -32,8 +39,11 @@ ColorButton::~ColorButton() {
|
|||||||
|
|
||||||
|
|
||||||
void ColorButton::resizeEvent(QResizeEvent * ) {
|
void ColorButton::resizeEvent(QResizeEvent * ) {
|
||||||
if (frame) back->setGeometry(rect());
|
if (frame) {
|
||||||
else back->setGeometry(8, 5, width() - 16, height() - 12);
|
back->setGeometry(rect());
|
||||||
|
} else {
|
||||||
|
back->setGeometry(8, 5, width() - 16, height() - 12);
|
||||||
|
}
|
||||||
label->setGeometry(back->geometry());
|
label->setGeometry(back->geometry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,11 +51,11 @@ void ColorButton::resizeEvent(QResizeEvent * ) {
|
|||||||
void ColorButton::mousePressEvent(QMouseEvent * e) {
|
void ColorButton::mousePressEvent(QMouseEvent * e) {
|
||||||
pp = e->pos();
|
pp = e->pos();
|
||||||
if (e->buttons().testFlag(Qt::RightButton)) {
|
if (e->buttons().testFlag(Qt::RightButton)) {
|
||||||
menu.popup(
|
menu->popup(
|
||||||
#if QT_VERSION_MAJOR <= 5
|
#if QT_VERSION_MAJOR <= 5
|
||||||
((QMouseEvent*)e)->globalPos()
|
static_cast<QMouseEvent*>(e)->globalPos()
|
||||||
#else
|
#else
|
||||||
((QMouseEvent*)e)->globalPosition().toPoint()
|
static_cast<QMouseEvent*>(e)->globalPosition().toPoint()
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -107,15 +117,19 @@ void ColorButton::changeEvent(QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void ColorButton::clicked() {
|
void ColorButton::clicked() {
|
||||||
QColor ret = QColorDialog::getColor(color(), nullptr, tr("Choose color"), options);
|
QColor ret = QColorDialog::getColor(color(), nullptr, tr("Choose color"), static_cast<QColorDialog::ColorDialogOptions>(options));
|
||||||
if (!ret.isValid()) return;
|
if (!ret.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setColor(ret);
|
setColor(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorButton::mix() {
|
void ColorButton::mix() {
|
||||||
QColor c(QApplication::clipboard()->text());
|
QColor c(QApplication::clipboard()->text());
|
||||||
if (!c.isValid()) return;
|
if (!c.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QColor sc = color();
|
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));
|
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) {
|
void ColorButton::setColor(const QColor & col) {
|
||||||
if (pal.color(label->backgroundRole()) == col) return;
|
if (pal.color(label->backgroundRole()) == col) return;
|
||||||
if (options.testFlag(QColorDialog::ShowAlphaChannel))
|
if (options & QColorDialog::ShowAlphaChannel) {
|
||||||
pal.setColor(label->backgroundRole(), col);
|
pal.setColor(label->backgroundRole(), col);
|
||||||
else
|
} else {
|
||||||
pal.setColor(label->backgroundRole(), QColor(col.red(), col.green(), col.blue()));
|
pal.setColor(label->backgroundRole(), QColor(col.red(), col.green(), col.blue()));
|
||||||
|
}
|
||||||
label->setPalette(pal);
|
label->setPalette(pal);
|
||||||
emit colorChanged(color());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,11 @@
|
|||||||
#ifndef COLORBUTTON_H
|
#ifndef COLORBUTTON_H
|
||||||
#define COLORBUTTON_H
|
#define COLORBUTTON_H
|
||||||
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QColorDialog>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QApplication>
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
|
||||||
|
class QFrame;
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT ColorButton: public QPushButton
|
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 useNativeDialog READ useNativeDialog WRITE setUseNativeDialog)
|
||||||
Q_PROPERTY(bool useAlphaChannel READ useAlphaChannel WRITE setUseAlphaChannel)
|
Q_PROPERTY(bool useAlphaChannel READ useAlphaChannel WRITE setUseAlphaChannel)
|
||||||
Q_PROPERTY(bool frameOnly READ frameOnly WRITE setFrameOnly)
|
Q_PROPERTY(bool frameOnly READ frameOnly WRITE setFrameOnly)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ColorButton(QWidget * parent = 0);
|
explicit ColorButton(QWidget * parent = nullptr);
|
||||||
~ColorButton();
|
~ColorButton() override;
|
||||||
|
|
||||||
QColor color() const {return pal.color(label->backgroundRole());}
|
QColor color() const;
|
||||||
bool useNativeDialog() const {return !options.testFlag(QColorDialog::DontUseNativeDialog);}
|
bool useNativeDialog() const;
|
||||||
bool useAlphaChannel() const {return options.testFlag(QColorDialog::ShowAlphaChannel);}
|
bool useAlphaChannel() const;
|
||||||
bool frameOnly() const {return frame;}
|
bool frameOnly() const {return frame;}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setColor(const QColor & col);
|
void setColor(const QColor & col);
|
||||||
void setUseNativeDialog(bool yes) {if (yes) options &= ~QColorDialog::DontUseNativeDialog; else options |= QColorDialog::DontUseNativeDialog;}
|
void setUseNativeDialog(bool yes);
|
||||||
void setUseAlphaChannel(bool yes) {if (yes) options |= QColorDialog::ShowAlphaChannel; else options &= ~QColorDialog::ShowAlphaChannel;}
|
void setUseAlphaChannel(bool yes);
|
||||||
void setFrameOnly(bool yes) {frame = yes; setFlat(frame); resizeEvent(0);}
|
void setFrameOnly(bool yes);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void clicked();
|
||||||
|
void copy();
|
||||||
|
void paste();
|
||||||
|
void mix();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void colorChanged(QColor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mousePressEvent(QMouseEvent * e);
|
void mousePressEvent(QMouseEvent * e) override;
|
||||||
void mouseMoveEvent(QMouseEvent * e);
|
void mouseMoveEvent(QMouseEvent * e) override;
|
||||||
void resizeEvent(QResizeEvent * );
|
void resizeEvent(QResizeEvent *) override;
|
||||||
void dragEnterEvent(QDragEnterEvent * e);
|
void dragEnterEvent(QDragEnterEvent * e) override;
|
||||||
void dropEvent(QDropEvent * e);
|
void dropEvent(QDropEvent * e) override;
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e) override;
|
||||||
|
|
||||||
QFrame * label;
|
QFrame * label;
|
||||||
QWidget * back;
|
QWidget * back;
|
||||||
QAction * a_copy, * a_paste, * a_mix;
|
QAction * a_copy, * a_paste, * a_mix;
|
||||||
QPalette pal;
|
QPalette pal;
|
||||||
QPoint pp;
|
QPoint pp;
|
||||||
QMenu menu;
|
QMenu * menu;
|
||||||
QColorDialog::ColorDialogOptions options;
|
int options;
|
||||||
bool frame;
|
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
|
#endif // COLORBUTTON_H
|
||||||
|
|||||||
@@ -1,58 +1,72 @@
|
|||||||
|
#include "ecombobox.h"
|
||||||
|
#include "clineedit.h"
|
||||||
|
#include "qabstractitemview.h"
|
||||||
|
#include "qad_types.h"
|
||||||
|
#include "qwidget.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include "ecombobox.h"
|
#include <QTreeView>
|
||||||
#include "qad_types.h"
|
#include <QLabel>
|
||||||
|
#include <QLayout>
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT EModel: public QStandardItemModel {
|
class EModel: public QStandardItemModel {
|
||||||
public:
|
public:
|
||||||
EModel(QObject * parent = 0): QStandardItemModel(parent) {
|
EModel(QObject * parent = nullptr): QStandardItemModel(parent) {
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
setSupportedDragActions(Qt::MoveAction);
|
setSupportedDragActions(Qt::MoveAction);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
protected:
|
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;
|
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||||
if (!index.isValid()) f |= Qt::ItemIsDropEnabled;
|
if (!index.isValid()) f |= Qt::ItemIsDropEnabled;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
Qt::DropActions supportedDragActions() const {return Qt::MoveAction;}
|
Qt::DropActions supportedDragActions() const override {return Qt::MoveAction;}
|
||||||
Qt::DropActions supportedDropActions() const {return Qt::MoveAction;}
|
Qt::DropActions supportedDropActions() const override {return Qt::MoveAction;}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EComboBox::EComboBox(QWidget * parent): QComboBox(parent) {
|
EComboBox::EComboBox(QWidget * parent)
|
||||||
setView(&iv);
|
: QComboBox(parent)
|
||||||
|
, iv(new QTreeView(this))
|
||||||
|
, header(new QWidget(this))
|
||||||
|
, icon(new QLabel(this))
|
||||||
|
, filter(new CLineEdit(this))
|
||||||
|
{
|
||||||
|
setView(iv);
|
||||||
setModel(new EModel());
|
setModel(new EModel());
|
||||||
iv.setTextElideMode(Qt::ElideMiddle);
|
iv->setTextElideMode(Qt::ElideMiddle);
|
||||||
iv.setRootIsDecorated(false);
|
iv->setRootIsDecorated(false);
|
||||||
iv.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
iv->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
iv.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
iv->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
iv.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
iv->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||||
iv.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
iv->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||||
iv.setMinimumHeight(100);
|
iv->setMinimumHeight(100);
|
||||||
icon.setPixmap(QPixmap(":/icons/edit-find.png"));
|
icon->setPixmap(QPixmap(":/icons/edit-find.png"));
|
||||||
icon.setScaledContents(true);
|
icon->setScaledContents(true);
|
||||||
icon.setFixedSize(preferredIconSize(1.2, this));
|
icon->setFixedSize(preferredIconSize(1.2, this));
|
||||||
ifont = nfont = font();
|
ifont = nfont = font();
|
||||||
ifont.setItalic(true);
|
ifont.setItalic(true);
|
||||||
#if QT_VERSION >= 0x040700
|
#if QT_VERSION >= 0x040700
|
||||||
filter.setPlaceholderText(tr("Filter"));
|
filter->setPlaceholderText(tr("Filter"));
|
||||||
filter.setFont(ifont);
|
filter->setFont(ifont);
|
||||||
#endif
|
#endif
|
||||||
header.setAutoFillBackground(true);
|
header->setAutoFillBackground(true);
|
||||||
header.setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
|
header->setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
|
||||||
header.layout()->setSpacing(2);
|
header->layout()->setSpacing(2);
|
||||||
header.layout()->setContentsMargins(2, 0, 0, 0);
|
header->layout()->setContentsMargins(2, 0, 0, 0);
|
||||||
header.layout()->addWidget(&icon);
|
header->layout()->addWidget(icon);
|
||||||
header.layout()->addWidget(&filter);
|
header->layout()->addWidget(filter);
|
||||||
header.setParent(iv.header());
|
header->setParent(iv->header());
|
||||||
connect(&filter, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
connect(filter, &CLineEdit::textChanged, this, [this](const QString & text){
|
||||||
|
EComboBox::filterChanged(text, false);
|
||||||
|
});
|
||||||
connect(model(), &EModel::layoutChanged, this, &EComboBox::rowsChanged);
|
connect(model(), &EModel::layoutChanged, this, &EComboBox::rowsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,12 +79,12 @@ QSize EComboBox::sizeHint() const {
|
|||||||
|
|
||||||
|
|
||||||
void EComboBox::showPopup() {
|
void EComboBox::showPopup() {
|
||||||
iv.setDragDropMode(isEditable() ? QAbstractItemView::InternalMove : QAbstractItemView::NoDragDrop);
|
iv->setDragDropMode(isEditable() ? QAbstractItemView::InternalMove : QAbstractItemView::NoDragDrop);
|
||||||
filterChanged(filter.text(), true);
|
filterChanged(filter->text(), true);
|
||||||
QComboBox::showPopup();
|
QComboBox::showPopup();
|
||||||
QRect r = iv.header()->rect();
|
QRect r = iv->header()->rect();
|
||||||
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
||||||
filter.setFocus();
|
filter->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +93,7 @@ void EComboBox::changeEvent(QEvent * e) {
|
|||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::LanguageChange:
|
case QEvent::LanguageChange:
|
||||||
#if QT_VERSION >= 0x040700
|
#if QT_VERSION >= 0x040700
|
||||||
filter.setPlaceholderText(tr("Filter"));
|
filter->setPlaceholderText(tr("Filter"));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -89,36 +103,40 @@ void EComboBox::changeEvent(QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void EComboBox::filterChanged(const QString & text, bool first) {
|
void EComboBox::filterChanged(const QString & text, bool first) {
|
||||||
if (filter.text().isEmpty()) filter.setFont(ifont);
|
if (filter->text().isEmpty()) {
|
||||||
else filter.setFont(nfont);
|
filter->setFont(ifont);
|
||||||
iv.hide();
|
} else {
|
||||||
QModelIndex pi = iv.rootIndex();
|
filter->setFont(nfont);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
iv.show();
|
iv->hide();
|
||||||
|
QModelIndex pi = iv->rootIndex();
|
||||||
|
int row_count = iv->model()->rowCount();
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
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();
|
||||||
if (first) return;
|
if (first) return;
|
||||||
hidePopup();
|
hidePopup();
|
||||||
showPopup();
|
showPopup();
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
QRect r = iv.header()->rect();
|
QRect r = iv->header()->rect();
|
||||||
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < iv.model()->rowCount(); ++i) {
|
for (int i = 0; i < row_count; ++i) {
|
||||||
iv.setRowHidden(i, pi, !iv.model()->index(i, 0, pi).data().toString().contains(
|
iv->setRowHidden(i, pi, !iv->model()->index(i, 0, pi).data().toString().contains(
|
||||||
#if QT_VERSION_MAJOR <= 5
|
#if QT_VERSION_MAJOR <= 5
|
||||||
QRegExp(text, Qt::CaseInsensitive)
|
QRegExp(text, Qt::CaseInsensitive)
|
||||||
#else
|
#else
|
||||||
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
||||||
#endif
|
#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();
|
qApp->processEvents();
|
||||||
QRect r = iv.header()->rect();
|
QRect r = iv->header()->rect();
|
||||||
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,39 +20,40 @@
|
|||||||
#ifndef ECOMBOBOX_H
|
#ifndef ECOMBOBOX_H
|
||||||
#define ECOMBOBOX_H
|
#define ECOMBOBOX_H
|
||||||
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QTreeView>
|
|
||||||
#include <QLabel>
|
|
||||||
#include "clineedit.h"
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
|
||||||
|
class CLineEdit;
|
||||||
|
class QLabel;
|
||||||
|
class QTreeView;
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT EComboBox: public QComboBox
|
class QAD_WIDGETS_EXPORT EComboBox: public QComboBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit EComboBox(QWidget * parent = 0);
|
explicit EComboBox(QWidget * parent = nullptr);
|
||||||
|
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void showPopup();
|
void showPopup() override;
|
||||||
|
|
||||||
private:
|
|
||||||
void changeEvent(QEvent *e);
|
|
||||||
|
|
||||||
QTreeView iv;
|
|
||||||
QWidget header;
|
|
||||||
QLabel icon;
|
|
||||||
CLineEdit filter;
|
|
||||||
QFont nfont, ifont;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void filterChanged(const QString & text, bool first = false);
|
void filterChanged(const QString & text, bool first);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void rowsChanged();
|
void rowsChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void changeEvent(QEvent *e) override;
|
||||||
|
|
||||||
|
QTreeView * iv;
|
||||||
|
QWidget * header;
|
||||||
|
QLabel * icon;
|
||||||
|
CLineEdit * filter;
|
||||||
|
QFont nfont, ifont;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ECOMBOBOX_H
|
#endif // ECOMBOBOX_H
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#include "evalspinbox.h"
|
#include "evalspinbox.h"
|
||||||
|
#include "qad_types.h"
|
||||||
|
#include "qpievaluator_p.h"
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionSpinBox>
|
||||||
|
#include <QMouseEvent>
|
||||||
#if QT_VERSION_MAJOR <= 5
|
#if QT_VERSION_MAJOR <= 5
|
||||||
# include <QRegExp>
|
# include <QRegExp>
|
||||||
#else
|
#else
|
||||||
# include <QRegularExpression>
|
# include <QRegularExpression>
|
||||||
#endif
|
#endif
|
||||||
#include <QPainter>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QStyleOptionSpinBox>
|
|
||||||
#include "qad_types.h"
|
|
||||||
#include "qpievaluator_p.h"
|
|
||||||
|
|
||||||
|
|
||||||
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
||||||
@@ -21,7 +22,6 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
|||||||
label = new QLabel(lineEdit());
|
label = new QLabel(lineEdit());
|
||||||
eval = new QPIEvaluator();
|
eval = new QPIEvaluator();
|
||||||
precision_ = -1;
|
precision_ = -1;
|
||||||
// label->hide();
|
|
||||||
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
|
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
|
||||||
icon_ok.load(":/icons/dialog-ok-apply.png");
|
icon_ok.load(":/icons/dialog-ok-apply.png");
|
||||||
icon_fail.load(":/icons/dialog-warning.png");
|
icon_fail.load(":/icons/dialog-warning.png");
|
||||||
@@ -35,14 +35,11 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
|||||||
cw->hide();
|
cw->hide();
|
||||||
cw_visible = false;
|
cw_visible = false;
|
||||||
calc_visible = true;
|
calc_visible = true;
|
||||||
//lineEdit()->setStyleSheet("color: darkgreen;");
|
|
||||||
//lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
|
|
||||||
cw->installEventFilter(this);
|
cw->installEventFilter(this);
|
||||||
status->installEventFilter(this);
|
status->installEventFilter(this);
|
||||||
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
|
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");
|
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) {
|
bool EvalSpinBox::eventFilter(QObject * o, QEvent * e) {
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
if (o == cw) clearMouseRelease((QMouseEvent * )e);
|
if (o == cw) {
|
||||||
|
clearMouseRelease(static_cast<QMouseEvent *>(e));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::Paint:
|
case QEvent::Paint:
|
||||||
if (o == status) statusPaintEvent();
|
if (o == status) {
|
||||||
if (o == cw) cwPaintEvent();
|
statusPaintEvent();
|
||||||
|
}
|
||||||
|
if (o == cw) {
|
||||||
|
cwPaintEvent();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default : break;
|
default : break;
|
||||||
}
|
}
|
||||||
@@ -141,8 +144,9 @@ void EvalSpinBox::textChanged_(const QString & text) {
|
|||||||
icon = icon_ok;
|
icon = icon_ok;
|
||||||
status->setToolTip("OK -> "+QString::number(value(), 'G', 10));
|
status->setToolTip("OK -> "+QString::number(value(), 'G', 10));
|
||||||
}
|
}
|
||||||
// qDebug() << "value =" << value();
|
if (pv != value()) {
|
||||||
if (pv != value()) emit valueChanged(value());
|
emit valueChanged(value());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
icon = icon_fail;
|
icon = icon_fail;
|
||||||
status->setToolTip(eval->error());
|
status->setToolTip(eval->error());
|
||||||
@@ -151,7 +155,7 @@ void EvalSpinBox::textChanged_(const QString & text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::setExpression_() {
|
void EvalSpinBox::setExpressionSlot() {
|
||||||
bool td = false;
|
bool td = false;
|
||||||
double pv = value();
|
double pv = value();
|
||||||
QString t = text();
|
QString t = text();
|
||||||
@@ -160,8 +164,7 @@ void EvalSpinBox::setExpression_() {
|
|||||||
t.chop(1);
|
t.chop(1);
|
||||||
}
|
}
|
||||||
if (eval->check(t)) {
|
if (eval->check(t)) {
|
||||||
/*if (eval.expression() == "0") lineEdit()->clear();
|
lineEdit()->setText(eval->expression());
|
||||||
else*/ lineEdit()->setText(eval->expression());
|
|
||||||
eval->evaluate();
|
eval->evaluate();
|
||||||
if (td) lineEdit()->setText(QString::number(value(), 'G', precision_ > 0 ? precision_ : 16));
|
if (td) lineEdit()->setText(QString::number(value(), 'G', precision_ > 0 ? precision_ : 16));
|
||||||
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
|
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
|
||||||
@@ -169,13 +172,8 @@ void EvalSpinBox::setExpression_() {
|
|||||||
} else {
|
} else {
|
||||||
icon = icon_fail;
|
icon = icon_fail;
|
||||||
status->setToolTip(eval->error());
|
status->setToolTip(eval->error());
|
||||||
// qDebug() << eval.expression();
|
|
||||||
}
|
}
|
||||||
if (!label->isHidden()) {
|
if (!label->isHidden()) {
|
||||||
// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
|
|
||||||
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
|
||||||
// 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("<html><head/><body><p><span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
||||||
else
|
else
|
||||||
@@ -188,29 +186,24 @@ void EvalSpinBox::setExpression_() {
|
|||||||
lineEdit()->setStyleSheet("");
|
lineEdit()->setStyleSheet("");
|
||||||
status->hide();
|
status->hide();
|
||||||
}
|
}
|
||||||
// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
|
|
||||||
//lineEdit()->setText("");
|
|
||||||
lineEdit()->blockSignals(false);
|
lineEdit()->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << "value =" << value();
|
|
||||||
if (pv != value()) emit valueChanged(value());
|
if (pv != value()) emit valueChanged(value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::setExpression(const QString & expr) {
|
void EvalSpinBox::setExpression(const QString & expr) {
|
||||||
lineEdit()->setText(expr);
|
lineEdit()->setText(expr);
|
||||||
//if (eval.expression() == "0") lineEdit()->clear();
|
|
||||||
cw->setVisible(text() != dt && cw_visible);
|
cw->setVisible(text() != dt && cw_visible);
|
||||||
setExpression_();
|
setExpressionSlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::setValue(double val) {
|
void EvalSpinBox::setValue(double val) {
|
||||||
lineEdit()->setText(QString::number(val, 'G', precision_ > 0 ? precision_ : 16));
|
lineEdit()->setText(QString::number(val, 'G', precision_ > 0 ? precision_ : 16));
|
||||||
//if (val == 0) lineEdit()->clear();
|
|
||||||
cw->setVisible(text() != dt && cw_visible);
|
cw->setVisible(text() != dt && cw_visible);
|
||||||
setExpression_();
|
setExpressionSlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -221,7 +214,7 @@ void EvalSpinBox::stepBy(int steps) {
|
|||||||
|
|
||||||
void EvalSpinBox::clear() {
|
void EvalSpinBox::clear() {
|
||||||
lineEdit()->setText(dt);
|
lineEdit()->setText(dt);
|
||||||
setExpression_();
|
setExpressionSlot();
|
||||||
cw->hide();
|
cw->hide();
|
||||||
resizeIcons();
|
resizeIcons();
|
||||||
emit cleared();
|
emit cleared();
|
||||||
@@ -259,7 +252,6 @@ QAbstractSpinBox::StepEnabled EvalSpinBox::stepEnabled() const {
|
|||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::focusInEvent(QFocusEvent * event) {
|
void EvalSpinBox::focusInEvent(QFocusEvent * event) {
|
||||||
// qDebug() << "focus_in";
|
|
||||||
label->hide();
|
label->hide();
|
||||||
status->show();
|
status->show();
|
||||||
lineEdit()->blockSignals(true);
|
lineEdit()->blockSignals(true);
|
||||||
@@ -273,29 +265,24 @@ void EvalSpinBox::focusInEvent(QFocusEvent * event) {
|
|||||||
|
|
||||||
void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
|
void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
|
||||||
QAbstractSpinBox::focusOutEvent(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()) {
|
||||||
// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
|
|
||||||
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
|
||||||
// else
|
|
||||||
// label->setText(eval.expression());
|
|
||||||
if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect())
|
|
||||||
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
||||||
else
|
} else {
|
||||||
label->setText("");
|
label->setText("");
|
||||||
if (calc_visible)
|
}
|
||||||
|
if (calc_visible) {
|
||||||
label->show();
|
label->show();
|
||||||
|
}
|
||||||
lineEdit()->blockSignals(true);
|
lineEdit()->blockSignals(true);
|
||||||
if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
|
if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
|
||||||
else status->hide();
|
else status->hide();
|
||||||
// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
|
|
||||||
//lineEdit()->clear();
|
|
||||||
lineEdit()->blockSignals(false);
|
lineEdit()->blockSignals(false);
|
||||||
resizeIcons();
|
resizeIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::wheelEvent(QWheelEvent * event) {
|
void EvalSpinBox::wheelEvent(QWheelEvent * event) {
|
||||||
if (event->modifiers().testFlag(Qt::ShiftModifier))
|
if (event->modifiers().testFlag(Qt::ShiftModifier)) {
|
||||||
stepByDouble(
|
stepByDouble(
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||||
event->delta()
|
event->delta()
|
||||||
@@ -303,13 +290,13 @@ void EvalSpinBox::wheelEvent(QWheelEvent * event) {
|
|||||||
event->angleDelta().y()
|
event->angleDelta().y()
|
||||||
#endif
|
#endif
|
||||||
> 0 ? 0.1 : -0.1);
|
> 0 ? 0.1 : -0.1);
|
||||||
else
|
} else {
|
||||||
QAbstractSpinBox::wheelEvent(event);
|
QAbstractSpinBox::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::stepByDouble(double steps) {
|
void EvalSpinBox::stepByDouble(double steps) {
|
||||||
//qDebug() << "step" << steps;
|
|
||||||
if (isReadOnly()) return;
|
if (isReadOnly()) return;
|
||||||
QString t = text();
|
QString t = text();
|
||||||
if (eval->check(t)) {
|
if (eval->check(t)) {
|
||||||
@@ -347,13 +334,7 @@ void EvalSpinBox::stepByDouble(double steps) {
|
|||||||
|
|
||||||
|
|
||||||
void EvalSpinBox::setDefaultText(const QString & t) {
|
void EvalSpinBox::setDefaultText(const QString & t) {
|
||||||
// bool def = (!cw->isHidden());
|
|
||||||
dt = t;
|
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);
|
cw->setVisible((eval->expression() != dt || (dt.isEmpty() && eval->expression() == "0")) && cw_visible);
|
||||||
resizeIcons();
|
resizeIcons();
|
||||||
}
|
}
|
||||||
@@ -368,7 +349,8 @@ void EvalSpinBox::setClearButtonVisible(bool visible) {
|
|||||||
|
|
||||||
void EvalSpinBox::setCalculationVisible(bool visible) {
|
void EvalSpinBox::setCalculationVisible(bool visible) {
|
||||||
calc_visible = visible;
|
calc_visible = visible;
|
||||||
setExpression_();
|
setExpressionSlot();
|
||||||
if (!calc_visible)
|
if (!calc_visible) {
|
||||||
label->hide();
|
label->hide();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,15 +20,14 @@
|
|||||||
#ifndef EVALSPINBOX_H
|
#ifndef EVALSPINBOX_H
|
||||||
#define EVALSPINBOX_H
|
#define EVALSPINBOX_H
|
||||||
|
|
||||||
#include <QAbstractSpinBox>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QAbstractSpinBox>
|
||||||
|
|
||||||
|
|
||||||
class QPIEvaluator;
|
class QPIEvaluator;
|
||||||
|
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox
|
class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -40,8 +39,8 @@ class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox
|
|||||||
Q_PROPERTY(int precision READ precision WRITE setPrecision)
|
Q_PROPERTY(int precision READ precision WRITE setPrecision)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EvalSpinBox(QWidget * parent = 0);
|
explicit EvalSpinBox(QWidget * parent = nullptr);
|
||||||
~EvalSpinBox();
|
~EvalSpinBox() override;
|
||||||
|
|
||||||
double value() const;
|
double value() const;
|
||||||
const QString & expression() const;
|
const QString & expression() const;
|
||||||
@@ -51,20 +50,45 @@ public:
|
|||||||
bool isCleared() const;
|
bool isCleared() const;
|
||||||
int precision() const {return precision_;}
|
int precision() const {return precision_;}
|
||||||
|
|
||||||
virtual void stepBy(int steps);
|
void stepBy(int steps) override;
|
||||||
virtual void clear();
|
void clear() override;
|
||||||
virtual QSize sizeHint() const;
|
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:
|
protected:
|
||||||
QString text() const {return QAbstractSpinBox::text();}
|
QString text() const {return QAbstractSpinBox::text();}
|
||||||
|
|
||||||
virtual StepEnabled stepEnabled() const;
|
StepEnabled stepEnabled() const override;
|
||||||
virtual void focusInEvent(QFocusEvent *event);
|
void focusInEvent(QFocusEvent *event) override;
|
||||||
virtual void focusOutEvent(QFocusEvent *event);
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
virtual void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
||||||
void stepByDouble(double steps);
|
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 * status;
|
||||||
QWidget * cw;
|
QWidget * cw;
|
||||||
QPIEvaluator * eval;
|
QPIEvaluator * eval;
|
||||||
@@ -77,32 +101,6 @@ protected:
|
|||||||
QString dt;
|
QString dt;
|
||||||
bool cw_visible, calc_visible;
|
bool cw_visible, calc_visible;
|
||||||
int precision_;
|
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
|
#endif // EVALSPINBOX_H
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ QIcon IconedLabel::icon() const {
|
|||||||
|
|
||||||
|
|
||||||
bool IconedLabel::event(QEvent * e) {
|
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());
|
setIconSize(iconSize());
|
||||||
|
}
|
||||||
return QFrame::event(e);
|
return QFrame::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,11 +44,12 @@ void IconedLabel::checkSpacing() {
|
|||||||
layout()->setSpacing(0);
|
layout()->setSpacing(0);
|
||||||
} else {
|
} else {
|
||||||
QStyle * s = style();
|
QStyle * s = style();
|
||||||
if (s)
|
if (s) {
|
||||||
layout()->setSpacing(s->layoutSpacing(QSizePolicy::Label, QSizePolicy::Label,
|
layout()->setSpacing(s->layoutSpacing(QSizePolicy::Label, QSizePolicy::Label,
|
||||||
dir_ <= Direction::RightToLeft ? Qt::Horizontal : Qt::Vertical));
|
dir_ <= Direction::RightToLeft ? Qt::Horizontal : Qt::Vertical));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize IconedLabel::realIconSize() const {
|
QSize IconedLabel::realIconSize() const {
|
||||||
@@ -79,9 +81,10 @@ void IconedLabel::setIconSize(const QSize & s) {
|
|||||||
|
|
||||||
void IconedLabel::setDirection(IconedLabel::Direction d) {
|
void IconedLabel::setDirection(IconedLabel::Direction d) {
|
||||||
dir_ = d;
|
dir_ = d;
|
||||||
if (layout() != 0)
|
if (layout()) {
|
||||||
delete layout();
|
delete layout();
|
||||||
QLayout * lay = new QBoxLayout((QBoxLayout::Direction)dir_);
|
}
|
||||||
|
QLayout * lay = new QBoxLayout(static_cast<QBoxLayout::Direction>(dir_));
|
||||||
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||||
lay->addWidget(&label_);
|
lay->addWidget(&label_);
|
||||||
lay->addWidget(&icon_);
|
lay->addWidget(&icon_);
|
||||||
|
|||||||
@@ -20,10 +20,9 @@
|
|||||||
#ifndef ICONEDLABEL_H
|
#ifndef ICONEDLABEL_H
|
||||||
#define ICONEDLABEL_H
|
#define ICONEDLABEL_H
|
||||||
|
|
||||||
|
#include "qad_widgets_export.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include "qad_types.h"
|
|
||||||
#include "qad_widgets_export.h"
|
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT IconedLabel: public QFrame
|
class QAD_WIDGETS_EXPORT IconedLabel: public QFrame
|
||||||
@@ -37,7 +36,7 @@ class QAD_WIDGETS_EXPORT IconedLabel: public QFrame
|
|||||||
public:
|
public:
|
||||||
enum Direction {LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop = 3};
|
enum Direction {LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop = 3};
|
||||||
|
|
||||||
explicit IconedLabel(QWidget * parent = 0);
|
explicit IconedLabel(QWidget * parent = nullptr);
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
@@ -46,8 +45,14 @@ public:
|
|||||||
|
|
||||||
QLabel * textLabel() {return &label_;}
|
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:
|
protected:
|
||||||
virtual bool event(QEvent * e);
|
bool event(QEvent * e) override;
|
||||||
void checkSpacing();
|
void checkSpacing();
|
||||||
QSize realIconSize() const;
|
QSize realIconSize() const;
|
||||||
|
|
||||||
@@ -55,15 +60,6 @@ protected:
|
|||||||
QIcon sicon_;
|
QIcon sicon_;
|
||||||
QSize size_;
|
QSize size_;
|
||||||
Direction dir_;
|
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
|
#endif // ICONEDLABEL_H
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "image_view.h"
|
#include "image_view.h"
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
|
||||||
ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
|
ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphicsPixmapItem) {
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setDragMode(QGraphicsView::NoDrag);
|
setDragMode(QGraphicsView::NoDrag);
|
||||||
@@ -17,9 +18,9 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
|
|||||||
setScene(new QGraphicsScene());
|
setScene(new QGraphicsScene());
|
||||||
setRenderHint(QPainter::Antialiasing, true);
|
setRenderHint(QPainter::Antialiasing, true);
|
||||||
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
item.setTransformationMode(Qt::SmoothTransformation);
|
item->setTransformationMode(Qt::SmoothTransformation);
|
||||||
item.setFlags(QGraphicsItem::GraphicsItemFlags());
|
item->setFlags(QGraphicsItem::GraphicsItemFlags());
|
||||||
scene()->addItem(&item);
|
scene()->addItem(item);
|
||||||
viewport()->setAutoFillBackground(false);
|
viewport()->setAutoFillBackground(false);
|
||||||
viewport()->installEventFilter(this);
|
viewport()->installEventFilter(this);
|
||||||
autofit_ = true;
|
autofit_ = true;
|
||||||
@@ -28,6 +29,7 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
|
|||||||
|
|
||||||
|
|
||||||
ImageView::~ImageView() {
|
ImageView::~ImageView() {
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ void ImageView::setViewInteractive(bool yes) {
|
|||||||
void ImageView::setImage(const QImage & i, bool save) {
|
void ImageView::setImage(const QImage & i, bool save) {
|
||||||
im_data.clear();
|
im_data.clear();
|
||||||
if (i.isNull()) {
|
if (i.isNull()) {
|
||||||
item.setPixmap(QPixmap());
|
item->setPixmap(QPixmap());
|
||||||
map = QPixmap();
|
map = QPixmap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ void ImageView::setImage(const QImage & i, bool save) {
|
|||||||
void ImageView::setImage(const QByteArray & i) {
|
void ImageView::setImage(const QByteArray & i) {
|
||||||
im_data = i;
|
im_data = i;
|
||||||
if (i.isEmpty()) {
|
if (i.isEmpty()) {
|
||||||
item.setPixmap(QPixmap());
|
item->setPixmap(QPixmap());
|
||||||
map = QPixmap();
|
map = QPixmap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -78,7 +80,7 @@ void ImageView::setImage(const QByteArray & i) {
|
|||||||
|
|
||||||
void ImageView::clear() {
|
void ImageView::clear() {
|
||||||
im_data.clear();
|
im_data.clear();
|
||||||
item.setPixmap(QPixmap());
|
item->setPixmap(QPixmap());
|
||||||
map = QPixmap();
|
map = QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ void ImageView::wheelEvent(QWheelEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
||||||
QMouseEvent * me = (QMouseEvent *)e;
|
QMouseEvent * me = reinterpret_cast<QMouseEvent *>(e);
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::Resize:
|
case QEvent::Resize:
|
||||||
adjustView();
|
adjustView();
|
||||||
@@ -137,23 +139,22 @@ void ImageView::adjustView() {
|
|||||||
ws *= devicePixelRatio();
|
ws *= devicePixelRatio();
|
||||||
#endif
|
#endif
|
||||||
int nw = map.size().boundedTo(ws).width();
|
int nw = map.size().boundedTo(ws).width();
|
||||||
item.setScale(1.);
|
item->setScale(1.);
|
||||||
if (nw > 0) {
|
if (nw > 0) {
|
||||||
qreal mp = map.width() / nw;
|
qreal mp = map.width() / nw;
|
||||||
if (mp > 1.) {
|
if (mp > 1.) {
|
||||||
QSize ss = map.size();
|
QSize ss = map.size();
|
||||||
item.setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
item.setScale(double(ss.width()) / item.pixmap().width());
|
item->setScale(double(ss.width()) / item->pixmap().width());
|
||||||
} else
|
} else
|
||||||
item.setPixmap(map);
|
item->setPixmap(map);
|
||||||
} else
|
} else
|
||||||
item.setPixmap(map);
|
item->setPixmap(map);
|
||||||
if (!autofit_) return;
|
if (!autofit_) return;
|
||||||
QRectF r = item.mapRectToScene(item.boundingRect());
|
QRectF r = item->mapRectToScene(item->boundingRect());
|
||||||
setSceneRect(r);
|
setSceneRect(r);
|
||||||
fitInView(r, Qt::KeepAspectRatio);
|
fitInView(r, Qt::KeepAspectRatio);
|
||||||
centerOn(r.center());
|
centerOn(r.center());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,11 @@
|
|||||||
#ifndef IMAGE_VIEW_H
|
#ifndef IMAGE_VIEW_H
|
||||||
#define IMAGE_VIEW_H
|
#define IMAGE_VIEW_H
|
||||||
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#include <QGraphicsPixmapItem>
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
|
||||||
|
class QGraphicsPixmapItem;
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView
|
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(QPixmap pixmap READ pixmap WRITE setPixmap)
|
||||||
Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive)
|
Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive)
|
||||||
public:
|
public:
|
||||||
ImageView(QWidget * parent = 0);
|
ImageView(QWidget * parent = nullptr);
|
||||||
~ImageView();
|
~ImageView() override;
|
||||||
|
|
||||||
void setImage(const QImage & i, bool save = true);
|
void setImage(const QImage & i, bool save = true);
|
||||||
void setImage(const QByteArray & i);
|
void setImage(const QByteArray & i);
|
||||||
QByteArray image() const {return im_data;}
|
QByteArray image() const {return im_data;}
|
||||||
QPixmap pixmap() const;
|
QPixmap pixmap() const;
|
||||||
bool viewInteractive() const {return interactive_;}
|
bool viewInteractive() const {return interactive_;}
|
||||||
|
|
||||||
void clear();
|
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:
|
public slots:
|
||||||
void autofit();
|
void autofit();
|
||||||
void setPixmap(QPixmap pixmap);
|
void setPixmap(QPixmap pixmap);
|
||||||
@@ -64,6 +51,18 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void clicked(QPointF, Qt::MouseButtons);
|
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
|
#endif // IMAGE_VIEW_H
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QLineEdit>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
#include <QTextOption>
|
#include <QTextOption>
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QPainter>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
# include <QWindow>
|
# include <QWindow>
|
||||||
#endif
|
#endif
|
||||||
@@ -24,7 +26,7 @@ Q_DECLARE_METATYPE(QCodeEdit::ACEntry)
|
|||||||
|
|
||||||
class _QCE_Viewport: public QWidget {
|
class _QCE_Viewport: public QWidget {
|
||||||
public:
|
public:
|
||||||
_QCE_Viewport(QWidget * p = 0): QWidget(p) {
|
_QCE_Viewport(QWidget * p = nullptr): QWidget(p) {
|
||||||
setObjectName("__qcodeedit_viewport__");
|
setObjectName("__qcodeedit_viewport__");
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
//setCursor(Qt::IBeamCursor);
|
//setCursor(Qt::IBeamCursor);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget
|
|||||||
friend class _QCE_Viewport;
|
friend class _QCE_Viewport;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QCodeEdit(QWidget * parent = 0);
|
QCodeEdit(QWidget * parent = nullptr);
|
||||||
~QCodeEdit();
|
~QCodeEdit();
|
||||||
|
|
||||||
enum ACClassType {
|
enum ACClassType {
|
||||||
@@ -177,7 +177,7 @@ private:
|
|||||||
bool hasBlockSelection() const;
|
bool hasBlockSelection() const;
|
||||||
void startBlockSelection();
|
void startBlockSelection();
|
||||||
void cancelBlockSelection();
|
void cancelBlockSelection();
|
||||||
void switchBlockSelection(QKeyEvent * ke = 0);
|
void switchBlockSelection(QKeyEvent * ke = nullptr);
|
||||||
bool removeBlockSelection(bool is_del);
|
bool removeBlockSelection(bool is_del);
|
||||||
void insertBlockSelection(QString text);
|
void insertBlockSelection(QString text);
|
||||||
void createBlockSelection();
|
void createBlockSelection();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "qcodeedit_completer_p.h"
|
#include "qcodeedit_completer_p.h"
|
||||||
|
#include "qad_types.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,23 @@
|
|||||||
#include "shortcuts.h"
|
#include "shortcuts.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QShortcut>
|
||||||
|
#include <QWidgetAction>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QToolBar>
|
||||||
|
|
||||||
|
|
||||||
|
/// ShortcutEdit
|
||||||
|
|
||||||
|
ShortcutEdit::ShortcutEdit(QWidget *parent) : CLineEdit(parent) {
|
||||||
|
ti = nullptr;
|
||||||
|
ca = nullptr;
|
||||||
|
connect(this, &CLineEdit::textChanged, this, &ShortcutEdit::textChangedSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShortcutEdit::keyPressEvent(QKeyEvent * e) {
|
void ShortcutEdit::keyPressEvent(QKeyEvent * e) {
|
||||||
@@ -6,14 +25,56 @@ void ShortcutEdit::keyPressEvent(QKeyEvent * e) {
|
|||||||
km &= ~Qt::KeypadModifier;
|
km &= ~Qt::KeypadModifier;
|
||||||
km &= ~Qt::GroupSwitchModifier;
|
km &= ~Qt::GroupSwitchModifier;
|
||||||
if (e->key() != Qt::Key_Control && e->key() != Qt::Key_Shift &&
|
if (e->key() != Qt::Key_Control && e->key() != Qt::Key_Shift &&
|
||||||
e->key() != Qt::Key_Alt && e->key() != Qt::Key_Meta)
|
e->key() != Qt::Key_Alt && e->key() != Qt::Key_Meta) {
|
||||||
setText(QKeySequence(km | e->key()).toString());
|
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) {
|
Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) {
|
||||||
aw = 0;
|
aw = nullptr;
|
||||||
QImage ti(QSize(16, 16), QImage::Format_ARGB32_Premultiplied);
|
QImage ti(QSize(16, 16), QImage::Format_ARGB32_Premultiplied);
|
||||||
QPainter p(&ti);
|
QPainter p(&ti);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_Clear);
|
p.setCompositionMode(QPainter::CompositionMode_Clear);
|
||||||
@@ -42,8 +103,9 @@ Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) {
|
|||||||
|
|
||||||
|
|
||||||
Shortcuts::~Shortcuts() {
|
Shortcuts::~Shortcuts() {
|
||||||
foreach (ShortcutEdit * i, edits)
|
for (ShortcutEdit * i : edits) {
|
||||||
delete i;
|
delete i;
|
||||||
|
}
|
||||||
edits.clear();
|
edits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,9 +122,12 @@ void Shortcuts::changeEvent(QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void Shortcuts::assignWindow(QWidget * w) {
|
void Shortcuts::assignWindow(QWidget * w) {
|
||||||
if (w == 0) return;
|
if (!w) {
|
||||||
while ((qobject_cast<QMainWindow * >(w) == 0) && (w->parentWidget() != 0))
|
return;
|
||||||
|
}
|
||||||
|
while (!(qobject_cast<QMainWindow * >(w)) && (w->parentWidget())) {
|
||||||
w = w->parentWidget();
|
w = w->parentWidget();
|
||||||
|
}
|
||||||
aw = qobject_cast<QMainWindow * >(w);
|
aw = qobject_cast<QMainWindow * >(w);
|
||||||
updateShortcuts();
|
updateShortcuts();
|
||||||
}
|
}
|
||||||
@@ -71,30 +136,38 @@ void Shortcuts::assignWindow(QWidget * w) {
|
|||||||
QStringList Shortcuts::actionTree(QAction * a) {
|
QStringList Shortcuts::actionTree(QAction * a) {
|
||||||
QStringList tree;
|
QStringList tree;
|
||||||
QList<QWidget * > aw = a->associatedWidgets();
|
QList<QWidget * > aw = a->associatedWidgets();
|
||||||
if (aw.size() == 0) return tree;
|
if (aw.size() == 0) {
|
||||||
QWidget * cw = 0;
|
return tree;
|
||||||
QMenu * tm;
|
}
|
||||||
QToolBar * tt;
|
for (QWidget * i : aw) {
|
||||||
foreach (QWidget * i, aw) {
|
auto tm = qobject_cast<QMenu * >(i);
|
||||||
tm = qobject_cast<QMenu * >(i);
|
if (!tm) {
|
||||||
if (tm == 0) continue;
|
continue;
|
||||||
cw = i;
|
}
|
||||||
while (cw != 0) {
|
auto cw = i;
|
||||||
|
while (cw) {
|
||||||
tm = qobject_cast<QMenu * >(cw);
|
tm = qobject_cast<QMenu * >(cw);
|
||||||
if (tm != 0) {
|
if (tm) {
|
||||||
if (!tm->title().isEmpty())
|
if (!tm->title().isEmpty()) {
|
||||||
tree.push_front(tm->title());
|
tree.push_front(tm->title());
|
||||||
|
}
|
||||||
cw = cw->parentWidget();
|
cw = cw->parentWidget();
|
||||||
} else break;
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!tree.isEmpty()) return tree;
|
|
||||||
}
|
}
|
||||||
foreach (QWidget * i, aw) {
|
if (!tree.isEmpty()) {
|
||||||
tt = qobject_cast<QToolBar * >(i);
|
return tree;
|
||||||
if (tt == 0) continue;
|
}
|
||||||
cw = i;
|
}
|
||||||
if (!tt->windowTitle().isEmpty())
|
for (QWidget * i : aw) {
|
||||||
|
auto tt = qobject_cast<QToolBar * >(i);
|
||||||
|
if (!tt) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!tt->windowTitle().isEmpty()) {
|
||||||
tree.push_front(tt->windowTitle());
|
tree.push_front(tt->windowTitle());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return tree;
|
return tree;
|
||||||
@@ -103,8 +176,10 @@ QStringList Shortcuts::actionTree(QAction * a) {
|
|||||||
|
|
||||||
QList<QPair<QString, QKeySequence> > Shortcuts::shortcuts() {
|
QList<QPair<QString, QKeySequence> > Shortcuts::shortcuts() {
|
||||||
QList<QPair<QString, QKeySequence> > l;
|
QList<QPair<QString, QKeySequence> > l;
|
||||||
foreach (ShortcutEdit * i, edits) {
|
for (const ShortcutEdit * i : edits) {
|
||||||
if (i->action()->objectName().isEmpty()) continue;
|
if (i->action()->objectName().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
l << QPair<QString, QKeySequence>(i->action()->objectName(), i->text());
|
l << QPair<QString, QKeySequence>(i->action()->objectName(), i->text());
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
@@ -124,19 +199,26 @@ void Shortcuts::clear() {
|
|||||||
|
|
||||||
|
|
||||||
bool Shortcuts::checkAction(QAction * a) {
|
bool Shortcuts::checkAction(QAction * a) {
|
||||||
if (a->menu() != 0) return false;
|
if (a->menu() || a->isSeparator() || a->text().isEmpty()) {
|
||||||
if (a->isSeparator()) return false;
|
return false;
|
||||||
if (a->text().isEmpty()) return false;
|
}
|
||||||
if (a->associatedWidgets().isEmpty()) return false;
|
if (a->associatedWidgets().isEmpty()) {
|
||||||
if (QString(a->metaObject()->className()) != "QAction") return false;
|
return false;
|
||||||
if (qobject_cast<QWidgetAction * >(a) != 0) return false;
|
}
|
||||||
|
if (QString(a->metaObject()->className()) != "QAction") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (qobject_cast<QWidgetAction * >(a)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Shortcuts::updateShortcuts() {
|
void Shortcuts::updateShortcuts() {
|
||||||
//return;
|
if (!aw || !active) {
|
||||||
if (aw == 0 || !active) return;
|
return;
|
||||||
|
}
|
||||||
hide();
|
hide();
|
||||||
int cpos = verticalScrollBar()->value();
|
int cpos = verticalScrollBar()->value();
|
||||||
clear();
|
clear();
|
||||||
@@ -150,12 +232,12 @@ void Shortcuts::updateShortcuts() {
|
|||||||
QStringList tree;
|
QStringList tree;
|
||||||
bool s = isSortingEnabled(), isFound;
|
bool s = isSortingEnabled(), isFound;
|
||||||
setSortingEnabled(false);
|
setSortingEnabled(false);
|
||||||
foreach (QAction * i, al) {
|
for (QAction * i : al) {
|
||||||
if (!checkAction(i)) continue;
|
if (!checkAction(i)) continue;
|
||||||
edits.push_back(new ShortcutEdit());
|
edits.push_back(new ShortcutEdit());
|
||||||
tree = actionTree(i);
|
tree = actionTree(i);
|
||||||
pi = invisibleRootItem();
|
pi = invisibleRootItem();
|
||||||
foreach (QString t, tree) {
|
for (const QString & t : tree) {
|
||||||
isFound = false;
|
isFound = false;
|
||||||
for (int j = 0; j < pi->childCount(); ++j) {
|
for (int j = 0; j < pi->childCount(); ++j) {
|
||||||
if (pi->child(j)->text(0) == t) {
|
if (pi->child(j)->text(0) == t) {
|
||||||
@@ -198,38 +280,55 @@ void Shortcuts::updateShortcuts() {
|
|||||||
|
|
||||||
|
|
||||||
void Shortcuts::commit() {
|
void Shortcuts::commit() {
|
||||||
foreach (ShortcutEdit * i, edits)
|
for (ShortcutEdit * i : edits) {
|
||||||
i->commit();
|
i->commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Shortcuts::reset() {
|
void Shortcuts::resetShortcuts() {
|
||||||
foreach (ShortcutEdit * i, edits)
|
for (ShortcutEdit * i : edits) {
|
||||||
i->reset();
|
i->reset();
|
||||||
|
}
|
||||||
updateShortcuts();
|
updateShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Shortcuts::filter(const QString & what) {
|
void Shortcuts::filter(const QString & what) {
|
||||||
hide();
|
hide();
|
||||||
for (int i = 0; i < topLevelItemCount(); ++i)
|
for (int i = 0; i < topLevelItemCount(); ++i) {
|
||||||
filterTree(topLevelItem(i), what);
|
filterTree(topLevelItem(i), what);
|
||||||
|
}
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) {
|
bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) {
|
||||||
if (f.isEmpty()) {
|
if (f.isEmpty()) {
|
||||||
for (int i = 0; i < ti->childCount(); ++i)
|
for (int i = 0; i < ti->childCount(); ++i) {
|
||||||
filterTree(ti->child(i), f);
|
filterTree(ti->child(i), f);
|
||||||
|
}
|
||||||
ti->setHidden(false);
|
ti->setHidden(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool isFound = false;
|
bool isFound = false;
|
||||||
for (int i = 0; i < ti->childCount(); ++i)
|
for (int i = 0; i < ti->childCount(); ++i) {
|
||||||
if (filterTree(ti->child(i), f)) isFound = true;
|
if (filterTree(ti->child(i), f)) {
|
||||||
|
isFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ti->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0 ||
|
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);
|
ti->setHidden(!isFound);
|
||||||
return isFound;
|
return isFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Shortcuts::updateEditorGeometries() {
|
||||||
|
for (ShortcutEdit * i : edits) {
|
||||||
|
i->setGeometry(visualRect(indexFromItem(i->ti, 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,20 +20,13 @@
|
|||||||
#ifndef SHORTCUTS_H
|
#ifndef SHORTCUTS_H
|
||||||
#define SHORTCUTS_H
|
#define SHORTCUTS_H
|
||||||
|
|
||||||
#include <QTreeWidget>
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QShortcut>
|
|
||||||
#include <QHeaderView>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QToolBar>
|
|
||||||
#include <QScrollBar>
|
|
||||||
#include <QWidgetAction>
|
|
||||||
#include "clineedit.h"
|
|
||||||
#include "qad_widgets_export.h"
|
#include "qad_widgets_export.h"
|
||||||
|
#include "clineedit.h"
|
||||||
|
#include <QTreeWidget>
|
||||||
|
|
||||||
|
|
||||||
|
class QMainWindow;
|
||||||
|
class ShortcutEdit;
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit
|
class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit
|
||||||
@@ -41,50 +34,48 @@ class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class Shortcuts;
|
friend class Shortcuts;
|
||||||
public:
|
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();}
|
void assignAction(QAction *a);
|
||||||
QAction * action() const {return ca;}
|
QAction *action() const;
|
||||||
bool isEmpty() const {return text().isEmpty();}
|
bool isEmpty() const;
|
||||||
void commit() {if (ca == 0) return; ca->setShortcut(QKeySequence(text()));}
|
void commit();
|
||||||
void reset() {if (ca == 0) return; setText(ca->shortcut().toString());}
|
void reset();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void textChanged_(QString t) {if (ti != 0) ti->setText(1, t);}
|
void textChangedSlot(QString t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void keyPressEvent(QKeyEvent * e);
|
void keyPressEvent(QKeyEvent * e) override;
|
||||||
|
|
||||||
QAction * ca;
|
QAction * ca;
|
||||||
QTreeWidgetItem * ti;
|
QTreeWidgetItem * ti;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class QAD_WIDGETS_EXPORT Shortcuts: public QTreeWidget
|
class QAD_WIDGETS_EXPORT Shortcuts: public QTreeWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Shortcuts(QWidget * parent = 0, bool on = true);
|
explicit Shortcuts(QWidget * parent = nullptr, bool on = true);
|
||||||
~Shortcuts();
|
~Shortcuts() override;
|
||||||
|
|
||||||
void assignWindow(QWidget * w);
|
void assignWindow(QWidget * w);
|
||||||
void setActive(bool on) {active = on;}
|
void setActive(bool on) {active = on;}
|
||||||
QList<QPair<QString, QKeySequence> > shortcuts();
|
|
||||||
QStringList actionTree(QAction * a);
|
QStringList actionTree(QAction * a);
|
||||||
static bool checkAction(QAction * a);
|
static bool checkAction(QAction * a);
|
||||||
|
QList<QPair<QString, QKeySequence> > shortcuts();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clear();
|
void clear();
|
||||||
void updateShortcuts();
|
void updateShortcuts();
|
||||||
void commit();
|
void commit();
|
||||||
void reset();
|
void resetShortcuts();
|
||||||
void filter(const QString & what);
|
void filter(const QString & what);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void updateEditorGeometries() {foreach (ShortcutEdit * i, edits) i->setGeometry(visualRect(indexFromItem(i->ti, 1)));}
|
virtual void updateEditorGeometries() override;
|
||||||
virtual void changeEvent(QEvent * );
|
virtual void changeEvent(QEvent *) override;
|
||||||
bool filterTree(QTreeWidgetItem *ti, QString f);
|
bool filterTree(QTreeWidgetItem *ti, QString f);
|
||||||
|
|
||||||
QMainWindow * aw;
|
QMainWindow * aw;
|
||||||
@@ -92,12 +83,6 @@ private:
|
|||||||
QIcon empty_icon;
|
QIcon empty_icon;
|
||||||
QFont bfont;
|
QFont bfont;
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void shortcutChanged(QAction * , QShortcut & );
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPINSLIDER_H
|
#endif // SPINSLIDER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user