code format
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "chardialog.h"
|
||||
|
||||
#include "ui_chardialog.h"
|
||||
|
||||
|
||||
@@ -11,20 +12,18 @@ CharDialog::CharDialog(QWidget * parent): QDialog(parent) {
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
c = QChar(j, i);
|
||||
k = c.category();
|
||||
if (chars.size() <= k)
|
||||
chars.resize(k + 1);
|
||||
if (chars.size() <= k) chars.resize(k + 1);
|
||||
if (!c.isPrint()) continue;
|
||||
|
||||
|
||||
chars[k].push_back(c);
|
||||
}
|
||||
}
|
||||
size = 30;
|
||||
QStringList cat;
|
||||
cat << tr("No Category") << tr("Mark NonSpacing") << tr("Mark SpacingCombining") << tr("Mark Enclosing")
|
||||
<< tr("Number DecimalDigit") << tr("Number Letter") << tr("Number Other") << tr("Separator Space")
|
||||
<< tr("Separator Line") << tr("Separator Paragraph") << tr("Other Control") << tr("Other Format")
|
||||
<< tr("Other Surrogate") << tr("Other PrivateUse") << tr("Other NotAssigned") << tr("Letter Uppercase")
|
||||
<< tr("Letter Lowercase") << tr("Letter Titlecase") << tr("Letter Modifier") << tr("Letter Other")
|
||||
cat << tr("No Category") << tr("Mark NonSpacing") << tr("Mark SpacingCombining") << tr("Mark Enclosing") << tr("Number DecimalDigit")
|
||||
<< tr("Number Letter") << tr("Number Other") << tr("Separator Space") << tr("Separator Line") << tr("Separator Paragraph")
|
||||
<< tr("Other Control") << tr("Other Format") << tr("Other Surrogate") << tr("Other PrivateUse") << tr("Other NotAssigned")
|
||||
<< tr("Letter Uppercase") << tr("Letter Lowercase") << tr("Letter Titlecase") << tr("Letter Modifier") << tr("Letter Other")
|
||||
<< tr("Punctuation Connector") << tr("Punctuation Dash") << tr("Punctuation Open") << tr("Punctuation Close")
|
||||
<< tr("Punctuation InitialQuote") << tr("Punctuation FinalQuote") << tr("Punctuation Other") << tr("Symbol Math")
|
||||
<< tr("Symbol Currency") << tr("Symbol Modifier") << tr("Symbol Other");
|
||||
@@ -53,13 +52,12 @@ void CharDialog::changeEvent(QEvent * e) {
|
||||
ui->retranslateUi(this);
|
||||
QStringList cat;
|
||||
cat << tr("No Category") << tr("Mark NonSpacing") << tr("Mark SpacingCombining") << tr("Mark Enclosing")
|
||||
<< tr("Number DecimalDigit") << tr("Number Letter") << tr("Number Other") << tr("Separator Space")
|
||||
<< tr("Separator Line") << tr("Separator Paragraph") << tr("Other Control") << tr("Other Format")
|
||||
<< tr("Other Surrogate") << tr("Other PrivateUse") << tr("Other NotAssigned") << tr("Letter Uppercase")
|
||||
<< tr("Letter Lowercase") << tr("Letter Titlecase") << tr("Letter Modifier") << tr("Letter Other")
|
||||
<< tr("Punctuation Connector") << tr("Punctuation Dash") << tr("Punctuation Open") << tr("Punctuation Close")
|
||||
<< tr("Punctuation InitialQuote") << tr("Punctuation FinalQuote") << tr("Punctuation Other") << tr("Symbol Math")
|
||||
<< tr("Symbol Currency") << tr("Symbol Modifier") << tr("Symbol Other");
|
||||
<< tr("Number DecimalDigit") << tr("Number Letter") << tr("Number Other") << tr("Separator Space") << tr("Separator Line")
|
||||
<< tr("Separator Paragraph") << tr("Other Control") << tr("Other Format") << tr("Other Surrogate") << tr("Other PrivateUse")
|
||||
<< tr("Other NotAssigned") << tr("Letter Uppercase") << tr("Letter Lowercase") << tr("Letter Titlecase")
|
||||
<< tr("Letter Modifier") << tr("Letter Other") << tr("Punctuation Connector") << tr("Punctuation Dash")
|
||||
<< tr("Punctuation Open") << tr("Punctuation Close") << tr("Punctuation InitialQuote") << tr("Punctuation FinalQuote")
|
||||
<< tr("Punctuation Other") << tr("Symbol Math") << tr("Symbol Currency") << tr("Symbol Modifier") << tr("Symbol Other");
|
||||
int pi = ui->comboCategory->currentIndex();
|
||||
ui->comboCategory->clear();
|
||||
ui->comboCategory->addItems(cat);
|
||||
@@ -71,15 +69,14 @@ void CharDialog::changeEvent(QEvent * e) {
|
||||
|
||||
bool CharDialog::eventFilter(QObject * o, QEvent * e) {
|
||||
if (o == ui->tableChars->viewport()) {
|
||||
if (e->type() != QEvent::Wheel)
|
||||
return QDialog::eventFilter(o, e);
|
||||
if (e->type() != QEvent::Wheel) return QDialog::eventFilter(o, e);
|
||||
qApp->sendEvent(ui->verticalScroll, e);
|
||||
}
|
||||
return QDialog::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void CharDialog::resizeEvent(QResizeEvent * ) {
|
||||
void CharDialog::resizeEvent(QResizeEvent *) {
|
||||
int r = ui->tableChars->contentsRect().height() / csize, c = ui->tableChars->contentsRect().width() / csize;
|
||||
ui->tableChars->setRowCount(r);
|
||||
ui->tableChars->setColumnCount(c);
|
||||
@@ -120,15 +117,17 @@ void CharDialog::on_verticalScroll_valueChanged(int index) {
|
||||
for (int i = 0; i < ui->tableChars->rowCount(); ++i) {
|
||||
for (int j = 0; j < ui->tableChars->columnCount(); ++j) {
|
||||
++ci;
|
||||
if (cur->size() > ci) ui->tableChars->item(i, j)->setText(cur->at(ci));
|
||||
else ui->tableChars->item(i, j)->setText(QString());
|
||||
if (cur->size() > ci)
|
||||
ui->tableChars->item(i, j)->setText(cur->at(ci));
|
||||
else
|
||||
ui->tableChars->item(i, j)->setText(QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CharDialog::on_spinSize_valueChanged(int index) {
|
||||
size = index;
|
||||
size = index;
|
||||
csize = size * 2;
|
||||
ui->tableChars->horizontalHeader()->setDefaultSectionSize(csize);
|
||||
ui->tableChars->verticalHeader()->setDefaultSectionSize(csize);
|
||||
|
||||
@@ -1,52 +1,53 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHARDIALOG_H
|
||||
#define CHARDIALOG_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class CharDialog;
|
||||
class CharDialog;
|
||||
}
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT CharDialog: public QDialog
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT CharDialog: public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CharDialog(QWidget * parent = nullptr);
|
||||
~CharDialog() override;
|
||||
|
||||
QChar selectedChar() {return sel_char;}
|
||||
|
||||
QChar selectedChar() { return sel_char; }
|
||||
void setCharFont(const QFont & f);
|
||||
|
||||
|
||||
private slots:
|
||||
void on_comboCategory_currentIndexChanged(int index);
|
||||
void on_verticalScroll_valueChanged(int index);
|
||||
void on_spinSize_valueChanged(int index);
|
||||
void on_tableChars_cellPressed(int row, int column);
|
||||
void on_tableChars_cellDoubleClicked(int , int ) {on_buttonBox_accepted();}
|
||||
void on_tableChars_cellDoubleClicked(int, int) { on_buttonBox_accepted(); }
|
||||
void on_buttonBox_accepted();
|
||||
void on_buttonBox_rejected() {reject();}
|
||||
void on_buttonBox_rejected() { reject(); }
|
||||
|
||||
signals:
|
||||
void charSelected(QChar ch);
|
||||
@@ -56,9 +57,9 @@ private:
|
||||
bool eventFilter(QObject * o, QEvent * e) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
void clear();
|
||||
|
||||
|
||||
Ui::CharDialog * ui;
|
||||
QVector<QVector<QChar> > chars;
|
||||
QVector<QVector<QChar>> chars;
|
||||
QVector<QChar> * cur;
|
||||
QChar sel_char;
|
||||
int size, csize;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "clineedit.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
@@ -12,7 +14,7 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
||||
cw->hide();
|
||||
cw->installEventFilter(this);
|
||||
connect(this, &QLineEdit::textChanged, this, &CLineEdit::textChangedSlot);
|
||||
int is = fontHeight(this);
|
||||
int is = fontHeight(this);
|
||||
QMargins m = textMargins();
|
||||
m.setRight(m.right() + (is * 1.2));
|
||||
setTextMargins(m);
|
||||
@@ -26,13 +28,9 @@ CLineEdit::~CLineEdit() {
|
||||
|
||||
bool CLineEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
switch (e->type()) {
|
||||
case QEvent::MouseButtonRelease:
|
||||
clearMouseRelease(static_cast<QMouseEvent *>(e));
|
||||
break;
|
||||
case QEvent::Paint:
|
||||
cwPaintEvent();
|
||||
break;
|
||||
default : break;
|
||||
case QEvent::MouseButtonRelease: clearMouseRelease(static_cast<QMouseEvent *>(e)); break;
|
||||
case QEvent::Paint: cwPaintEvent(); break;
|
||||
default: break;
|
||||
}
|
||||
return QLineEdit::eventFilter(o, e);
|
||||
}
|
||||
@@ -73,7 +71,7 @@ void CLineEdit::setDefaultText(const QString & t, bool set_text) {
|
||||
}
|
||||
|
||||
|
||||
void CLineEdit::clearMouseRelease(QMouseEvent *e) {
|
||||
void CLineEdit::clearMouseRelease(QMouseEvent * e) {
|
||||
if (cw->rect().contains(e->pos())) {
|
||||
clearClick();
|
||||
}
|
||||
|
||||
@@ -1,48 +1,54 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CLINEEDIT_H
|
||||
#define CLINEEDIT_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_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
|
||||
|
||||
public:
|
||||
explicit CLineEdit(QWidget * parent = nullptr);
|
||||
~CLineEdit() override;
|
||||
|
||||
const QString & defaultText() const {return dt;}
|
||||
|
||||
const QString & defaultText() const { return dt; }
|
||||
|
||||
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);
|
||||
|
||||
signals:
|
||||
void cleared();
|
||||
|
||||
private slots:
|
||||
void clearMouseRelease(QMouseEvent *e);
|
||||
void clearMouseRelease(QMouseEvent * e);
|
||||
void textChangedSlot(QString text);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
#include "colorbutton.h"
|
||||
|
||||
#include "qclipboard.h"
|
||||
#include "qcolor.h"
|
||||
#include "qmenu.h"
|
||||
#include <QColorDialog>
|
||||
#include <QMouseEvent>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QFrame>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QColorDialog>
|
||||
#include <QDrag>
|
||||
#include <QFrame>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
ColorButton::ColorButton(QWidget * parent): QPushButton(parent), menu(new QMenu(this)) {
|
||||
frame = false;
|
||||
frame = false;
|
||||
options = QColorDialog::ShowAlphaChannel;
|
||||
back = new QWidget(this);
|
||||
back = new QWidget(this);
|
||||
back->setAutoFillBackground(true);
|
||||
back->show();
|
||||
pal = back->palette();
|
||||
@@ -23,8 +25,8 @@ ColorButton::ColorButton(QWidget * parent): QPushButton(parent), menu(new QMenu(
|
||||
label->setAutoFillBackground(true);
|
||||
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()));
|
||||
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()));
|
||||
@@ -38,7 +40,7 @@ ColorButton::~ColorButton() {
|
||||
}
|
||||
|
||||
|
||||
void ColorButton::resizeEvent(QResizeEvent * ) {
|
||||
void ColorButton::resizeEvent(QResizeEvent *) {
|
||||
if (frame) {
|
||||
back->setGeometry(rect());
|
||||
} else {
|
||||
@@ -53,11 +55,11 @@ void ColorButton::mousePressEvent(QMouseEvent * e) {
|
||||
if (e->buttons().testFlag(Qt::RightButton)) {
|
||||
menu->popup(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
static_cast<QMouseEvent*>(e)->globalPos()
|
||||
static_cast<QMouseEvent *>(e)->globalPos()
|
||||
#else
|
||||
static_cast<QMouseEvent*>(e)->globalPosition().toPoint()
|
||||
static_cast<QMouseEvent *>(e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
return;
|
||||
}
|
||||
QPushButton::mousePressEvent(e);
|
||||
@@ -68,7 +70,7 @@ void ColorButton::mouseMoveEvent(QMouseEvent * e) {
|
||||
if (e->buttons().testFlag(Qt::LeftButton)) {
|
||||
if ((e->pos() - pp).manhattanLength() > QApplication::startDragDistance()) {
|
||||
setDown(false);
|
||||
QDrag * drag = new QDrag(this);
|
||||
QDrag * drag = new QDrag(this);
|
||||
QMimeData * data = new QMimeData();
|
||||
data->setColorData(color());
|
||||
drag->setMimeData(data);
|
||||
@@ -88,7 +90,7 @@ void ColorButton::dragEnterEvent(QDragEnterEvent * e) {
|
||||
|
||||
void ColorButton::dropEvent(QDropEvent * e) {
|
||||
const QMimeData * data = e->mimeData();
|
||||
QColor c = qvariant_cast<QColor>(data->colorData());
|
||||
QColor c = qvariant_cast<QColor>(data->colorData());
|
||||
if (c.isValid()) {
|
||||
setColor(c);
|
||||
return;
|
||||
@@ -105,13 +107,12 @@ void ColorButton::dropEvent(QDropEvent * e) {
|
||||
void ColorButton::changeEvent(QEvent * e) {
|
||||
QPushButton::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
a_copy->setText(tr("Copy"));
|
||||
a_paste->setText(tr("Paste"));
|
||||
a_mix->setText(tr("Mix with clipboard"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange:
|
||||
a_copy->setText(tr("Copy"));
|
||||
a_paste->setText(tr("Paste"));
|
||||
a_mix->setText(tr("Mix with clipboard"));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,4 +199,3 @@ void ColorButton::paste() {
|
||||
void ColorButton::copy() {
|
||||
QApplication::clipboard()->setText(color().name());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef COLORBUTTON_H
|
||||
#define COLORBUTTON_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
class QFrame;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ColorButton: public QPushButton
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT ColorButton: public QPushButton {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor)
|
||||
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 = nullptr);
|
||||
~ColorButton() override;
|
||||
@@ -41,7 +42,7 @@ public:
|
||||
QColor color() const;
|
||||
bool useNativeDialog() const;
|
||||
bool useAlphaChannel() const;
|
||||
bool frameOnly() const {return frame;}
|
||||
bool frameOnly() const { return frame; }
|
||||
|
||||
public slots:
|
||||
void setColor(const QColor & col);
|
||||
@@ -64,11 +65,11 @@ private:
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
void dragEnterEvent(QDragEnterEvent * e) override;
|
||||
void dropEvent(QDropEvent * e) override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
void changeEvent(QEvent * e) override;
|
||||
|
||||
QFrame * label;
|
||||
QWidget * back;
|
||||
QAction * a_copy, * a_paste, * a_mix;
|
||||
QAction *a_copy, *a_paste, *a_mix;
|
||||
QPalette pal;
|
||||
QPoint pp;
|
||||
QMenu * menu;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#include "ecombobox.h"
|
||||
|
||||
#include "clineedit.h"
|
||||
#include "qabstractitemview.h"
|
||||
#include "qad_types.h"
|
||||
#include "qwidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
|
||||
|
||||
class EModel: public QStandardItemModel {
|
||||
@@ -18,6 +20,7 @@ public:
|
||||
setSupportedDragActions(Qt::MoveAction);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Qt::ItemFlags flags(const QModelIndex & index) const override {
|
||||
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
@@ -25,20 +28,18 @@ protected:
|
||||
return f;
|
||||
}
|
||||
#if QT_VERSION >= 0x050000
|
||||
Qt::DropActions supportedDragActions() const override {return Qt::MoveAction;}
|
||||
Qt::DropActions supportedDropActions() const override {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)
|
||||
, iv(new QTreeView(this))
|
||||
, header(new QWidget(this))
|
||||
, icon(new QLabel(this))
|
||||
, filter(new CLineEdit(this))
|
||||
{
|
||||
, filter(new CLineEdit(this)) {
|
||||
setView(iv);
|
||||
setModel(new EModel());
|
||||
iv->setTextElideMode(Qt::ElideMiddle);
|
||||
@@ -64,9 +65,7 @@ EComboBox::EComboBox(QWidget * parent)
|
||||
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(filter, &CLineEdit::textChanged, this, [this](const QString & text) { EComboBox::filterChanged(text, false); });
|
||||
connect(model(), &EModel::layoutChanged, this, &EComboBox::rowsChanged);
|
||||
}
|
||||
|
||||
@@ -91,13 +90,12 @@ void EComboBox::showPopup() {
|
||||
void EComboBox::changeEvent(QEvent * e) {
|
||||
QComboBox::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
case QEvent::LanguageChange:
|
||||
#if QT_VERSION >= 0x040700
|
||||
filter->setPlaceholderText(tr("Filter"));
|
||||
filter->setPlaceholderText(tr("Filter"));
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +108,7 @@ void EComboBox::filterChanged(const QString & text, bool first) {
|
||||
}
|
||||
iv->hide();
|
||||
QModelIndex pi = iv->rootIndex();
|
||||
int row_count = iv->model()->rowCount();
|
||||
int row_count = iv->model()->rowCount();
|
||||
if (text.isEmpty()) {
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
iv->setRowHidden(i, pi, false);
|
||||
@@ -126,13 +124,15 @@ void EComboBox::filterChanged(const QString & text, bool first) {
|
||||
return;
|
||||
}
|
||||
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->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->show();
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ECOMBOBOX_H
|
||||
#define ECOMBOBOX_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
|
||||
@@ -29,12 +30,12 @@ class QLabel;
|
||||
class QTreeView;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT EComboBox: public QComboBox
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT EComboBox: public QComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EComboBox(QWidget * parent = nullptr);
|
||||
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
@@ -47,7 +48,7 @@ signals:
|
||||
void rowsChanged();
|
||||
|
||||
private:
|
||||
void changeEvent(QEvent *e) override;
|
||||
void changeEvent(QEvent * e) override;
|
||||
|
||||
QTreeView * iv;
|
||||
QWidget * header;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#include "evalspinbox.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
#include "qpievaluator_p.h"
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QStyle>
|
||||
#include <QStyleOptionSpinBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QTimer>
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
# include <QRegExp>
|
||||
#else
|
||||
@@ -17,10 +19,10 @@
|
||||
|
||||
|
||||
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
||||
status = new QWidget(lineEdit());
|
||||
cw = new QWidget(lineEdit());
|
||||
label = new QLabel(lineEdit());
|
||||
eval = new QPIEvaluator();
|
||||
status = new QWidget(lineEdit());
|
||||
cw = new QWidget(lineEdit());
|
||||
label = new QLabel(lineEdit());
|
||||
eval = new QPIEvaluator();
|
||||
precision_ = -1;
|
||||
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
|
||||
icon_ok.load(":/icons/dialog-ok-apply.png");
|
||||
@@ -33,7 +35,7 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
|
||||
cw->setCursor(Qt::ArrowCursor);
|
||||
cw->setToolTip(tr("Clear"));
|
||||
cw->hide();
|
||||
cw_visible = false;
|
||||
cw_visible = false;
|
||||
calc_visible = true;
|
||||
cw->installEventFilter(this);
|
||||
status->installEventFilter(this);
|
||||
@@ -66,7 +68,7 @@ bool EvalSpinBox::eventFilter(QObject * o, QEvent * e) {
|
||||
cwPaintEvent();
|
||||
}
|
||||
break;
|
||||
default : break;
|
||||
default: break;
|
||||
}
|
||||
return QAbstractSpinBox::eventFilter(o, e);
|
||||
}
|
||||
@@ -77,13 +79,13 @@ void EvalSpinBox::resizeIcons() {
|
||||
int tm = (lineEdit()->height() - is + 1) / 2;
|
||||
QStyleOptionFrame so;
|
||||
so.initFrom(lineEdit());
|
||||
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &so, lineEdit());
|
||||
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &so, lineEdit());
|
||||
QMargins m = lineEdit()->textMargins();
|
||||
int lwh = label->sizeHint().width();
|
||||
int lwh = label->sizeHint().width();
|
||||
label->setGeometry(lineEdit()->width() - m.left() - lwh + r.x() - 2,
|
||||
m.top() + r.y() + (r.height() - fontMetrics().height() + 1) / 2,
|
||||
lwh,// - 2*tm - (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)),
|
||||
lineEdit()->height() - 2*tm);
|
||||
m.top() + r.y() + (r.height() - fontMetrics().height() + 1) / 2,
|
||||
lwh, // - 2*tm - (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)),
|
||||
lineEdit()->height() - 2 * tm);
|
||||
status->setGeometry(lineEdit()->width() - (is + tm) * (cw->isVisible() ? 2 : 1), tm, is, is);
|
||||
cw->setGeometry(lineEdit()->width() - (is + tm) * 1, tm, is, is);
|
||||
m.setRight((is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)));
|
||||
@@ -139,10 +141,10 @@ void EvalSpinBox::textChanged_(const QString & text) {
|
||||
eval->evaluate();
|
||||
if (td) {
|
||||
icon = icon_calc;
|
||||
status->setToolTip("Enter to calc -> "+QString::number(value(), 'G', 10));
|
||||
status->setToolTip("Enter to calc -> " + QString::number(value(), 'G', 10));
|
||||
} else {
|
||||
icon = icon_ok;
|
||||
status->setToolTip("OK -> "+QString::number(value(), 'G', 10));
|
||||
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
|
||||
}
|
||||
if (pv != value()) {
|
||||
emit valueChanged(value());
|
||||
@@ -156,7 +158,7 @@ void EvalSpinBox::textChanged_(const QString & text) {
|
||||
|
||||
|
||||
void EvalSpinBox::setExpressionSlot() {
|
||||
bool td = false;
|
||||
bool td = false;
|
||||
double pv = value();
|
||||
QString t = text();
|
||||
if (t.endsWith('=')) {
|
||||
@@ -174,8 +176,10 @@ void EvalSpinBox::setExpressionSlot() {
|
||||
status->setToolTip(eval->error());
|
||||
}
|
||||
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><span style=\"color:#005500;\">-> " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
|
||||
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>");
|
||||
else
|
||||
label->setText("");
|
||||
lineEdit()->blockSignals(true);
|
||||
@@ -265,8 +269,10 @@ void EvalSpinBox::focusInEvent(QFocusEvent * event) {
|
||||
|
||||
void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
|
||||
QAbstractSpinBox::focusOutEvent(event);
|
||||
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>");
|
||||
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>");
|
||||
} else {
|
||||
label->setText("");
|
||||
}
|
||||
@@ -274,8 +280,10 @@ void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
|
||||
label->show();
|
||||
}
|
||||
lineEdit()->blockSignals(true);
|
||||
if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
|
||||
else status->hide();
|
||||
if (!eval->isCorrect())
|
||||
lineEdit()->setStyleSheet("color: darkred;");
|
||||
else
|
||||
status->hide();
|
||||
lineEdit()->blockSignals(false);
|
||||
resizeIcons();
|
||||
}
|
||||
@@ -285,11 +293,13 @@ void EvalSpinBox::wheelEvent(QWheelEvent * event) {
|
||||
if (event->modifiers().testFlag(Qt::ShiftModifier)) {
|
||||
stepByDouble(
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
event->delta()
|
||||
event->delta()
|
||||
#else
|
||||
event->angleDelta().y()
|
||||
event->angleDelta().y()
|
||||
#endif
|
||||
> 0 ? 0.1 : -0.1);
|
||||
> 0
|
||||
? 0.1
|
||||
: -0.1);
|
||||
} else {
|
||||
QAbstractSpinBox::wheelEvent(event);
|
||||
}
|
||||
@@ -311,20 +321,20 @@ void EvalSpinBox::stepByDouble(double steps) {
|
||||
t.insert(pos, QString::number(v));
|
||||
} else {
|
||||
double v = steps;
|
||||
t = QString::number(v) + t;
|
||||
t = QString::number(v) + t;
|
||||
}
|
||||
#else
|
||||
QRegularExpression re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)");
|
||||
QRegularExpressionMatchIterator i = re.globalMatch(t);
|
||||
if (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
double v = t.mid(match.capturedStart(), match.capturedLength()).toDouble();
|
||||
double v = t.mid(match.capturedStart(), match.capturedLength()).toDouble();
|
||||
v += steps;
|
||||
t.remove(match.capturedStart(), match.capturedLength());
|
||||
t.insert(match.capturedStart(), QString::number(v));
|
||||
} else {
|
||||
double v = steps;
|
||||
t = QString::number(v) + t;
|
||||
t = QString::number(v) + t;
|
||||
}
|
||||
#endif
|
||||
eval->check(t);
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EVALSPINBOX_H
|
||||
#define EVALSPINBOX_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QAbstractSpinBox>
|
||||
|
||||
|
||||
@@ -28,8 +29,7 @@ class QPIEvaluator;
|
||||
class QLabel;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
|
||||
Q_PROPERTY(QString expression READ expression WRITE setExpression USER true)
|
||||
@@ -44,11 +44,11 @@ public:
|
||||
|
||||
double value() const;
|
||||
const QString & expression() const;
|
||||
const QString & defaultText() const {return dt;}
|
||||
bool isClearButtonVisible() const {return cw_visible;}
|
||||
bool isCalculationVisible() const {return calc_visible;}
|
||||
const QString & defaultText() const { return dt; }
|
||||
bool isClearButtonVisible() const { return cw_visible; }
|
||||
bool isCalculationVisible() const { return calc_visible; }
|
||||
bool isCleared() const;
|
||||
int precision() const {return precision_;}
|
||||
int precision() const { return precision_; }
|
||||
|
||||
void stepBy(int steps) override;
|
||||
void clear() override;
|
||||
@@ -60,15 +60,15 @@ public slots:
|
||||
void setDefaultText(const QString & t);
|
||||
void setClearButtonVisible(bool visible);
|
||||
void setCalculationVisible(bool visible);
|
||||
void setPrecision(int precision) {precision_ = precision;}
|
||||
void setPrecision(int precision) { precision_ = precision; }
|
||||
|
||||
protected:
|
||||
QString text() const {return QAbstractSpinBox::text();}
|
||||
QString text() const { return QAbstractSpinBox::text(); }
|
||||
|
||||
StepEnabled stepEnabled() const override;
|
||||
void focusInEvent(QFocusEvent *event) override;
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void focusInEvent(QFocusEvent * event) override;
|
||||
void focusOutEvent(QFocusEvent * event) override;
|
||||
void wheelEvent(QWheelEvent * event) override;
|
||||
|
||||
void stepByDouble(double steps);
|
||||
|
||||
@@ -84,7 +84,7 @@ signals:
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject * o, QEvent * e) override;
|
||||
void resizeEvent(QResizeEvent * ) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
void changeEvent(QEvent * e) override;
|
||||
void statusPaintEvent();
|
||||
void cwPaintEvent();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "iconedlabel.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QStyle>
|
||||
#include <QEvent>
|
||||
|
||||
|
||||
IconedLabel::IconedLabel(QWidget * parent): QFrame(parent) {
|
||||
@@ -45,8 +47,8 @@ void IconedLabel::checkSpacing() {
|
||||
} else {
|
||||
QStyle * s = style();
|
||||
if (s) {
|
||||
layout()->setSpacing(s->layoutSpacing(QSizePolicy::Label, QSizePolicy::Label,
|
||||
dir_ <= Direction::RightToLeft ? Qt::Horizontal : Qt::Vertical));
|
||||
layout()->setSpacing(
|
||||
s->layoutSpacing(QSizePolicy::Label, QSizePolicy::Label, dir_ <= Direction::RightToLeft ? Qt::Horizontal : Qt::Vertical));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +74,7 @@ void IconedLabel::setIcon(const QIcon & i) {
|
||||
|
||||
|
||||
void IconedLabel::setIconSize(const QSize & s) {
|
||||
size_ = s;
|
||||
size_ = s;
|
||||
QSize sz = realIconSize();
|
||||
icon_.setPixmap(sicon_.pixmap(sz));
|
||||
icon_.setFixedSize(sz);
|
||||
|
||||
@@ -1,49 +1,55 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ICONEDLABEL_H
|
||||
#define ICONEDLABEL_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
#include <QLabel>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT IconedLabel: public QFrame
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT IconedLabel: public QFrame {
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Direction)
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
|
||||
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
|
||||
|
||||
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 = nullptr);
|
||||
|
||||
QString text() const;
|
||||
QIcon icon() const;
|
||||
QSize iconSize() const {return size_;}
|
||||
Direction direction() const {return dir_;}
|
||||
QSize iconSize() const { return size_; }
|
||||
Direction direction() const { return dir_; }
|
||||
|
||||
QLabel * textLabel() {return &label_;}
|
||||
QLabel * textLabel() { return &label_; }
|
||||
|
||||
public slots:
|
||||
void setText(const QString & t);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "image_view.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsScene>
|
||||
#include <QBuffer>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QDebug>
|
||||
#include <QWheelEvent>
|
||||
#include <qmath.h>
|
||||
|
||||
|
||||
@@ -23,7 +24,7 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphic
|
||||
scene()->addItem(item);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
viewport()->installEventFilter(this);
|
||||
autofit_ = true;
|
||||
autofit_ = true;
|
||||
interactive_ = false;
|
||||
}
|
||||
|
||||
@@ -57,7 +58,8 @@ void ImageView::setImage(const QImage & i, bool save) {
|
||||
return;
|
||||
}
|
||||
if (save) {
|
||||
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
|
||||
QBuffer b(&im_data);
|
||||
b.open(QIODevice::ReadWrite);
|
||||
i.save(&b, "png");
|
||||
b.close();
|
||||
}
|
||||
@@ -99,7 +101,7 @@ void ImageView::mousePressEvent(QMouseEvent * e) {
|
||||
void ImageView::wheelEvent(QWheelEvent * e) {
|
||||
if (!e->modifiers().testFlag(Qt::ControlModifier) || !viewInteractive()) return;
|
||||
double scl = 1. + e->angleDelta().y() / 500.;
|
||||
autofit_ = false;
|
||||
autofit_ = false;
|
||||
scale(scl, scl);
|
||||
}
|
||||
|
||||
@@ -107,13 +109,10 @@ void ImageView::wheelEvent(QWheelEvent * e) {
|
||||
bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
||||
QMouseEvent * me = reinterpret_cast<QMouseEvent *>(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::Resize:
|
||||
adjustView();
|
||||
break;
|
||||
case QEvent::Resize: adjustView(); break;
|
||||
case QEvent::MouseButtonPress:
|
||||
prev_pos = me->pos();
|
||||
if (me->buttons().testFlag(Qt::RightButton) && !autofit_ && viewInteractive())
|
||||
viewport()->setCursor(Qt::ClosedHandCursor);
|
||||
if (me->buttons().testFlag(Qt::RightButton) && !autofit_ && viewInteractive()) viewport()->setCursor(Qt::ClosedHandCursor);
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
viewport()->unsetCursor();
|
||||
|
||||
@@ -1,46 +1,47 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IMAGE_VIEW_H
|
||||
#define IMAGE_VIEW_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
|
||||
class QGraphicsPixmapItem;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive)
|
||||
|
||||
public:
|
||||
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;}
|
||||
QByteArray image() const { return im_data; }
|
||||
QPixmap pixmap() const;
|
||||
bool viewInteractive() const {return interactive_;}
|
||||
bool viewInteractive() const { return interactive_; }
|
||||
void clear();
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "mathmatrixedit.h"
|
||||
|
||||
#include "matrixedit.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
#include "qad_types.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
|
||||
@@ -39,12 +41,10 @@ void MathMatrixEdit::setReadOnly(bool yes) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class MathMatrixEditFactory: public QVariantEditorFactoryBase {
|
||||
public:
|
||||
MathMatrixEditFactory() {}
|
||||
QWidget * createEditor() override {return new MathMatrixEdit();}
|
||||
QWidget * createEditor() override { return new MathMatrixEdit(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MATH_MATRIX_EDIT_H
|
||||
#define MATH_MATRIX_EDIT_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
#include <QWidget>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class MatrixEdit;
|
||||
@@ -32,10 +33,11 @@ class QAD_WIDGETS_EXPORT MathMatrixEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
|
||||
public:
|
||||
explicit MathMatrixEdit(QWidget * parent = nullptr);
|
||||
~MathMatrixEdit() override;
|
||||
|
||||
|
||||
QVariant value() const;
|
||||
bool isReadOnly() const;
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "mathvectoredit.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
#include "qad_types.h"
|
||||
|
||||
#include "matrixedit.h"
|
||||
#include "qad_types.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
|
||||
@@ -39,12 +41,10 @@ void MathVectorEdit::setReadOnly(bool yes) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class MathVectorEditFactory: public QVariantEditorFactoryBase {
|
||||
public:
|
||||
MathVectorEditFactory() {}
|
||||
virtual QWidget * createEditor() override {return new MathVectorEdit();}
|
||||
virtual QWidget * createEditor() override { return new MathVectorEdit(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MATH_VECTOR_EDIT_H
|
||||
#define MATH_VECTOR_EDIT_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
#include <QWidget>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class MatrixEdit;
|
||||
@@ -32,13 +33,14 @@ class QAD_WIDGETS_EXPORT MathVectorEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
|
||||
public:
|
||||
explicit MathVectorEdit(QWidget * parent = nullptr);
|
||||
~MathVectorEdit() override;
|
||||
|
||||
|
||||
QVariant value() const;
|
||||
bool isReadOnly() const;
|
||||
|
||||
|
||||
public slots:
|
||||
void setValue(const QVariant & v);
|
||||
void setReadOnly(bool yes);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "matrixedit.h"
|
||||
|
||||
#include "ui_matrixedit.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
|
||||
@@ -9,7 +11,7 @@ MatrixEdit::MatrixEdit(QWidget * parent): QWidget(parent) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
||||
ui->table->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
||||
#endif
|
||||
connect(ui->table, SIGNAL(cellChanged(int,int)), this, SIGNAL(changed()));
|
||||
connect(ui->table, SIGNAL(cellChanged(int, int)), this, SIGNAL(changed()));
|
||||
ro = false;
|
||||
}
|
||||
|
||||
@@ -52,18 +54,14 @@ void MatrixEdit::clear(bool ident) {
|
||||
i->setText((ident && (r == c)) ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MatrixEdit::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +82,8 @@ QVector<double> MatrixEdit::vector() const {
|
||||
}
|
||||
|
||||
|
||||
QVector<QVector<double> > MatrixEdit::matrix() const {
|
||||
QVector<QVector<double> > ret;
|
||||
QVector<QVector<double>> MatrixEdit::matrix() const {
|
||||
QVector<QVector<double>> ret;
|
||||
if (ui->table->columnCount() < 1 || ui->table->rowCount() < 1) return ret;
|
||||
int cc = ui->table->columnCount();
|
||||
ret.resize(ui->table->rowCount());
|
||||
@@ -123,7 +121,7 @@ void MatrixEdit::setVector(const QVector<double> & v) {
|
||||
}
|
||||
|
||||
|
||||
void MatrixEdit::setMatrix(const QVector<QVector<double> > & v) {
|
||||
void MatrixEdit::setMatrix(const QVector<QVector<double>> & v) {
|
||||
clear();
|
||||
if (v.isEmpty()) return;
|
||||
if (v[0].isEmpty()) return;
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MATRIXEDIT_H
|
||||
#define MATRIXEDIT_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class MatrixEdit;
|
||||
class MatrixEdit;
|
||||
}
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT MatrixEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MatrixEdit(QWidget * parent = nullptr);
|
||||
~MatrixEdit() override;
|
||||
@@ -39,9 +41,9 @@ public:
|
||||
void setReadOnly(bool yes);
|
||||
|
||||
QVector<double> vector() const;
|
||||
QVector<QVector<double> > matrix() const;
|
||||
QVector<QVector<double>> matrix() const;
|
||||
void setVector(const QVector<double> & v);
|
||||
void setMatrix(const QVector<QVector<double> > & v);
|
||||
void setMatrix(const QVector<QVector<double>> & v);
|
||||
|
||||
private slots:
|
||||
void on_spinRows_valueChanged(int cnt);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "clineedit.h"
|
||||
#include "clineeditplugin.h"
|
||||
|
||||
#include "clineedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ CLineEditPlugin::CLineEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void CLineEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString CLineEditPlugin::domXml() const {
|
||||
QString CLineEditPlugin::includeFile() const {
|
||||
return QLatin1String("clineedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class CLineEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class CLineEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // CLINEEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "colorbutton.h"
|
||||
#include "colorbuttonplugin.h"
|
||||
|
||||
#include "colorbutton.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ ColorButtonPlugin::ColorButtonPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void ColorButtonPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString ColorButtonPlugin::domXml() const {
|
||||
QString ColorButtonPlugin::includeFile() const {
|
||||
return QLatin1String("colorbutton.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class ColorButtonPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class ColorButtonPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // COLORBUTTONPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "ecombobox.h"
|
||||
#include "ecomboboxplugin.h"
|
||||
|
||||
#include "ecombobox.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ EComboBoxPlugin::EComboBoxPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void EComboBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString EComboBoxPlugin::domXml() const {
|
||||
QString EComboBoxPlugin::includeFile() const {
|
||||
return QLatin1String("ecombobox.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class EComboBoxPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class EComboBoxPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // ECOMBOBOXPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "evalspinbox.h"
|
||||
#include "evalspinboxplugin.h"
|
||||
|
||||
#include "evalspinbox.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ EvalSpinBoxPlugin::EvalSpinBoxPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void EvalSpinBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString EvalSpinBoxPlugin::domXml() const {
|
||||
QString EvalSpinBoxPlugin::includeFile() const {
|
||||
return QLatin1String("evalspinbox.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class EvalSpinBoxPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class EvalSpinBoxPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // EVALSPINBOXPLUGIN_H
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class IconedLabelPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class IconedLabelPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // ICONEDLABEPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "image_view.h"
|
||||
#include "imageviewplugin.h"
|
||||
|
||||
#include "image_view.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ ImageViewPlugin::ImageViewPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void ImageViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString ImageViewPlugin::domXml() const {
|
||||
QString ImageViewPlugin::includeFile() const {
|
||||
return QLatin1String("image_view.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class ImageViewPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class ImageViewPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "iconedlabel.h"
|
||||
#include "iconedlabelplugin.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +10,7 @@ IconedLabelPlugin::IconedLabelPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void IconedLabelPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +66,3 @@ QString IconedLabelPlugin::domXml() const {
|
||||
QString IconedLabelPlugin::includeFile() const {
|
||||
return QLatin1String("iconedlabel.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "qad_widgets.h"
|
||||
#include "spinsliderplugin.h"
|
||||
#include "colorbuttonplugin.h"
|
||||
#include "shortcutsplugin.h"
|
||||
|
||||
#include "clineeditplugin.h"
|
||||
#include "colorbuttonplugin.h"
|
||||
#include "ecomboboxplugin.h"
|
||||
#include "evalspinboxplugin.h"
|
||||
#include "iconedlabelplugin.h"
|
||||
#include "imageviewplugin.h"
|
||||
#include "qcodeeditplugin.h"
|
||||
#include "qipeditplugin.h"
|
||||
#include "qpiconfigplugin.h"
|
||||
#include "qpiconsoleplugin.h"
|
||||
#include "qpointeditplugin.h"
|
||||
#include "qrecteditplugin.h"
|
||||
#include "ecomboboxplugin.h"
|
||||
#include "qpiconsoleplugin.h"
|
||||
#include "iconedlabelplugin.h"
|
||||
#include "qcodeeditplugin.h"
|
||||
#include "qvarianteditplugin.h"
|
||||
#include "qpiconfigplugin.h"
|
||||
#include "evalspinboxplugin.h"
|
||||
#include "imageviewplugin.h"
|
||||
#include "scroll_spin_boxplugin.h"
|
||||
#include "rangesliderplugin.h"
|
||||
#include "scroll_spin_boxplugin.h"
|
||||
#include "shortcutsplugin.h"
|
||||
#include "spinsliderplugin.h"
|
||||
|
||||
|
||||
QADWidgets::QADWidgets(QObject * parent): QObject(parent) {
|
||||
@@ -39,7 +40,7 @@ QADWidgets::QADWidgets(QObject * parent): QObject(parent) {
|
||||
}
|
||||
|
||||
|
||||
QList<QDesignerCustomWidgetInterface * > QADWidgets::customWidgets() const {
|
||||
QList<QDesignerCustomWidgetInterface *> QADWidgets::customWidgets() const {
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
#ifndef QAD_WIDGETS_H
|
||||
#define QAD_WIDGETS_H
|
||||
|
||||
#include <QtDesigner/QtDesigner>
|
||||
#include <QtCore/qplugin.h>
|
||||
#include <QtDesigner/QtDesigner>
|
||||
|
||||
class QADWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
class QADWidgets
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetCollectionInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "qad.widgets")
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit QADWidgets(QObject * parent = 0);
|
||||
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
|
||||
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const;
|
||||
|
||||
private:
|
||||
QList<QDesignerCustomWidgetInterface * > m_widgets;
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> m_widgets;
|
||||
};
|
||||
|
||||
#endif // QAD_WIDGETS_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qcodeedit.h"
|
||||
#include "qcodeeditplugin.h"
|
||||
|
||||
#include "qcodeedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QCodeEditPlugin::QCodeEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QCodeEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QCodeEditPlugin::domXml() const {
|
||||
QString QCodeEditPlugin::includeFile() const {
|
||||
return QLatin1String("qcodeedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QCodeEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QCodeEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QCODEEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qipedit.h"
|
||||
#include "qipeditplugin.h"
|
||||
|
||||
#include "qipedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QIPEditPlugin::QIPEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QIPEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QIPEditPlugin::domXml() const {
|
||||
QString QIPEditPlugin::includeFile() const {
|
||||
return QLatin1String("qipedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QIPEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QIPEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QIPEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qpiconfigwidget.h"
|
||||
#include "qpiconfigplugin.h"
|
||||
|
||||
#include "qpiconfigwidget.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QPIConfigPlugin::QPIConfigPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QPIConfigPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QPIConfigPlugin::domXml() const {
|
||||
QString QPIConfigPlugin::includeFile() const {
|
||||
return QLatin1String("qpiconfigwidget.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QPIConfigPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QPIConfigPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONFIGPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qpiconsole.h"
|
||||
#include "qpiconsoleplugin.h"
|
||||
|
||||
#include "qpiconsole.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QPIConsolePlugin::QPIConsolePlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QPIConsolePlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QPIConsolePlugin::domXml() const {
|
||||
QString QPIConsolePlugin::includeFile() const {
|
||||
return QLatin1String("qpiconsole.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QPIConsolePlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QPIConsolePlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QPICONSOLEPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qpointedit.h"
|
||||
#include "qpointeditplugin.h"
|
||||
|
||||
#include "qpointedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QPointEditPlugin::QPointEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QPointEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QPointEditPlugin::domXml() const {
|
||||
QString QPointEditPlugin::includeFile() const {
|
||||
return QLatin1String("qpointedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QPointEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QPointEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QPOINTEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qrectedit.h"
|
||||
#include "qrecteditplugin.h"
|
||||
|
||||
#include "qrectedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QRectEditPlugin::QRectEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QRectEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QRectEditPlugin::domXml() const {
|
||||
QString QRectEditPlugin::includeFile() const {
|
||||
return QLatin1String("qrectedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QRectEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QRectEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QRECTEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qvariantedit.h"
|
||||
#include "qvarianteditplugin.h"
|
||||
|
||||
#include "qvariantedit.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ QVariantEditPlugin::QVariantEditPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void QVariantEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString QVariantEditPlugin::domXml() const {
|
||||
QString QVariantEditPlugin::includeFile() const {
|
||||
return QLatin1String("qvariantedit.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class QVariantEditPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class QVariantEditPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // QVARIANTEDITPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "rangeslider.h"
|
||||
#include "rangesliderplugin.h"
|
||||
|
||||
#include "rangeslider.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ RangeSliderPlugin::RangeSliderPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void RangeSliderPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString RangeSliderPlugin::domXml() const {
|
||||
QString RangeSliderPlugin::includeFile() const {
|
||||
return QLatin1String("rangeslider.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class RangeSliderPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class RangeSliderPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // RANGESLIDERPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "scroll_spin_box.h"
|
||||
#include "scroll_spin_boxplugin.h"
|
||||
|
||||
#include "scroll_spin_box.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ ScrollSpinBoxPlugin::ScrollSpinBoxPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void ScrollSpinBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString ScrollSpinBoxPlugin::domXml() const {
|
||||
QString ScrollSpinBoxPlugin::includeFile() const {
|
||||
return QLatin1String("scroll_spin_box.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class ScrollSpinBoxPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class ScrollSpinBoxPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // SCROLLSPINBOXPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "shortcuts.h"
|
||||
#include "shortcutsplugin.h"
|
||||
|
||||
#include "shortcuts.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ ShortcutsPlugin::ShortcutsPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void ShortcutsPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString ShortcutsPlugin::domXml() const {
|
||||
QString ShortcutsPlugin::includeFile() const {
|
||||
return QLatin1String("shortcuts.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class ShortcutsPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class ShortcutsPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "spinslider.h"
|
||||
#include "spinsliderplugin.h"
|
||||
|
||||
#include "spinslider.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ SpinSliderPlugin::SpinSliderPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void SpinSliderPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString SpinSliderPlugin::domXml() const {
|
||||
QString SpinSliderPlugin::includeFile() const {
|
||||
return QLatin1String("spinslider.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class SpinSliderPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class SpinSliderPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "propertystorage_editor.h"
|
||||
|
||||
#include "propertystorage.h"
|
||||
#include "qvariantedit.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QToolButton>
|
||||
|
||||
@@ -24,7 +26,7 @@ void PropertyStorageEditor::clear() {
|
||||
|
||||
|
||||
bool PropertyStorageEditor::isEmpty() const {
|
||||
return static_cast<QGridLayout*>(layout())->count() == 0;
|
||||
return static_cast<QGridLayout *>(layout())->count() == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +34,9 @@ void PropertyStorageEditor::setStorage(PropertyStorage * s) {
|
||||
clear();
|
||||
storage = s;
|
||||
if (!storage) return;
|
||||
int r = 0;
|
||||
auto layoutProps = static_cast<QGridLayout*>(layout());
|
||||
for (const PropertyStorage::Property & p : *storage) {
|
||||
int r = 0;
|
||||
auto layoutProps = static_cast<QGridLayout *>(layout());
|
||||
for (const PropertyStorage::Property & p: *storage) {
|
||||
auto lbl = new QLabel(p.name);
|
||||
_widgets << lbl;
|
||||
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
|
||||
@@ -44,9 +46,12 @@ void PropertyStorageEditor::setStorage(PropertyStorage * s) {
|
||||
ve->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
ve->setMinimumWidth(50);
|
||||
connect(ve, SIGNAL(valueChanged(QVariant)), this, SIGNAL(changed()));
|
||||
layoutProps->addWidget(ve, r, 1); _widgets << ve;
|
||||
lbl = new QLabel(p.comment); lbl->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
layoutProps->addWidget(lbl, r, 2); _widgets << lbl;
|
||||
layoutProps->addWidget(ve, r, 1);
|
||||
_widgets << ve;
|
||||
lbl = new QLabel(p.comment);
|
||||
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
layoutProps->addWidget(lbl, r, 2);
|
||||
_widgets << lbl;
|
||||
++r;
|
||||
}
|
||||
}
|
||||
@@ -55,13 +60,13 @@ void PropertyStorageEditor::setStorage(PropertyStorage * s) {
|
||||
void PropertyStorageEditor::applyProperties() {
|
||||
if (!storage) return;
|
||||
QList<PropertyStorage::Property> & props(storage->properties());
|
||||
auto layoutProps = static_cast<QGridLayout*>(layout());
|
||||
auto layoutProps = static_cast<QGridLayout *>(layout());
|
||||
for (int r = 0; r < layoutProps->rowCount(); ++r) {
|
||||
if (layoutProps->itemAtPosition(r, 0) == nullptr || layoutProps->itemAtPosition(r, 1) == nullptr) {
|
||||
continue;
|
||||
}
|
||||
QLabel * lbl = qobject_cast<QLabel * >(layoutProps->itemAtPosition(r, 0)->widget());
|
||||
QVariantEdit * ve = qobject_cast<QVariantEdit * >(layoutProps->itemAtPosition(r, 1)->widget());
|
||||
QLabel * lbl = qobject_cast<QLabel *>(layoutProps->itemAtPosition(r, 0)->widget());
|
||||
QVariantEdit * ve = qobject_cast<QVariantEdit *>(layoutProps->itemAtPosition(r, 1)->widget());
|
||||
if (lbl == nullptr || ve == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,49 +1,51 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROPERTYSTORAGEEDITOR_H
|
||||
#define PROPERTYSTORAGEEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class PropertyStorage;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT PropertyStorageEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PropertyStorageEditor(QWidget * parent = nullptr);
|
||||
~PropertyStorageEditor() override;
|
||||
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
void setStorage(PropertyStorage * s);
|
||||
void applyProperties();
|
||||
|
||||
|
||||
signals:
|
||||
void resetStorageRequest(PropertyStorage * );
|
||||
void resetStorageRequest(PropertyStorage *);
|
||||
void changed();
|
||||
|
||||
private:
|
||||
QList<QWidget*> _widgets;
|
||||
QList<QWidget *> _widgets;
|
||||
PropertyStorage * storage;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
#include "qcodeedit.h"
|
||||
#include "ui_qcodeedit.h"
|
||||
#include "qcodeedit_completer_p.h"
|
||||
|
||||
#include "ecombobox.h"
|
||||
#include "qad_types.h"
|
||||
#include "iconedlabel.h"
|
||||
#include <QLayout>
|
||||
#include "qad_types.h"
|
||||
#include "qcodeedit_completer_p.h"
|
||||
#include "ui_qcodeedit.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QScrollBar>
|
||||
#include <QDesktopServices>
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPainter>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBlock>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTextOption>
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlock>
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QPainter>
|
||||
#include <QPlainTextEdit>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
# include <QWindow>
|
||||
#endif
|
||||
@@ -39,21 +41,20 @@ public:
|
||||
}
|
||||
|
||||
QCodeEdit * ce;
|
||||
|
||||
};
|
||||
|
||||
|
||||
QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
overlay = nullptr;
|
||||
prev_lc = auto_comp_pl = cur_search_ind = pos_press = pos_el_press = -1;
|
||||
timer_parse = 0;
|
||||
timer_parse = 0;
|
||||
_ignore_focus_out = _destructor = _replacing = cursor_state = block_sel_state = false;
|
||||
_first = true;
|
||||
comment_text = "//";
|
||||
_first = true;
|
||||
comment_text = "//";
|
||||
qRegisterMetaType<QTextCursor>();
|
||||
qRegisterMetaType<QCodeEdit::ACEntry>();
|
||||
ui->setupUi(this);
|
||||
overlay = new _QCE_Viewport(ui->textCode->viewport());
|
||||
overlay = new _QCE_Viewport(ui->textCode->viewport());
|
||||
overlay->ce = this;
|
||||
overlay->show();
|
||||
ui->widgetSearch->hide();
|
||||
@@ -86,7 +87,7 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
lbl_help[lhF1]->setIcon(QIcon(":/icons/f1.png"));
|
||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||
help_visible = true;
|
||||
completer = new QCodeEditCompleter();
|
||||
completer = new QCodeEditCompleter();
|
||||
|
||||
cursor_width = qMax<int>(qRound(fontHeight(this) / 10.), 1);
|
||||
ui->textCode->setCursorWidth(0);
|
||||
@@ -98,28 +99,34 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
#else
|
||||
ui->textLines->setFixedWidth(ui->textLines->fontMetrics().width(" "));
|
||||
#endif
|
||||
|
||||
QAction * a = new QAction(this); ui->textCode->addAction(a);
|
||||
|
||||
QAction * a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Shift+Tab"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(deindent()));
|
||||
a = new QAction(this); ui->textCode->addAction(a);
|
||||
a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Ctrl+D"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(deleteLine()));
|
||||
a = new QAction(this); ui->textCode->addAction(a);
|
||||
a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Ctrl+Return"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(newLine()));
|
||||
a = new QAction(this); ui->textCode->addAction(a);
|
||||
a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Ctrl+Up"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(scrollUp()));
|
||||
a = new QAction(this); ui->textCode->addAction(a);
|
||||
a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Ctrl+Down"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(scrollDown()));
|
||||
a = new QAction(this); ui->textCode->addAction(a);
|
||||
a = new QAction(this);
|
||||
ui->textCode->addAction(a);
|
||||
a->setShortcut(QKeySequence("Ctrl+Shift+Return"));
|
||||
a->setShortcutContext(Qt::WidgetShortcut);
|
||||
connect(a, SIGNAL(triggered()), this, SLOT(newLineBefore()));
|
||||
@@ -135,7 +142,7 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
connect(a, SIGNAL(triggered(bool)), this, SLOT(search_triggered()));
|
||||
addAction(a);
|
||||
|
||||
connect(completer, SIGNAL(itemDoubleClicked(QTreeWidgetItem * ,int)), this, SLOT(commitCompletition()));
|
||||
connect(completer, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(commitCompletition()));
|
||||
connect(completer, SIGNAL(commit()), this, SLOT(commitCompletition()));
|
||||
connect(completer, SIGNAL(gotoHRef(QCodeEdit::ACEntry)), this, SLOT(gotoHelpHRef(QCodeEdit::ACEntry)));
|
||||
connect(ui->textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), ui->textLines->verticalScrollBar(), SLOT(setValue(int)));
|
||||
@@ -150,7 +157,12 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent), ui(new Ui::QCodeEdit) {
|
||||
connect(ui->comboSearch->lineEdit(), SIGNAL(returnPressed()), this, SLOT(searchNext()));
|
||||
connect(ui->comboReplace->lineEdit(), SIGNAL(returnPressed()), this, SLOT(on_buttonReplaceSearch_clicked()));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
connect(qApp, &QGuiApplication::focusWindowChanged, this, [this](QWindow*w){if (w == nullptr) {hideHelp(); completer->hide();}});
|
||||
connect(qApp, &QGuiApplication::focusWindowChanged, this, [this](QWindow * w) {
|
||||
if (w == nullptr) {
|
||||
hideHelp();
|
||||
completer->hide();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
updateLines();
|
||||
timer_blink = startTimer(QApplication::cursorFlashTime() / 2);
|
||||
@@ -191,8 +203,7 @@ void QCodeEdit::setDocument(QTextDocument * doc) {
|
||||
documentChanged(nullptr);
|
||||
return;
|
||||
}
|
||||
if (!qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()))
|
||||
doc->setDocumentLayout(new QPlainTextDocumentLayout(doc));
|
||||
if (!qobject_cast<QPlainTextDocumentLayout *>(doc->documentLayout())) doc->setDocumentLayout(new QPlainTextDocumentLayout(doc));
|
||||
ui->textCode->setDocument(doc);
|
||||
cursor_width = qMax<int>(qRound(fontHeight(this) / 10.), 1);
|
||||
ui->textCode->setCursorWidth(0);
|
||||
@@ -303,14 +314,26 @@ void QCodeEdit::registerAutoCompletitionClass(int id, QCodeEdit::ACClassType ac_
|
||||
|
||||
|
||||
int QCodeEdit::skipRange(const QString & s, int pos, QChar oc, QChar cc, QChar sc) {
|
||||
int cnt = 0;
|
||||
int cnt = 0;
|
||||
bool skip = false;
|
||||
for (int i = pos - 1; i >= 0; --i) {
|
||||
QChar c = s[i];
|
||||
if (skip) {skip = false; continue;}
|
||||
if (c == sc) {skip = true; continue;}
|
||||
if (c == cc) {cnt++; continue;}
|
||||
if (c == oc) {cnt--; if (cnt == 0) return i;}
|
||||
if (skip) {
|
||||
skip = false;
|
||||
continue;
|
||||
}
|
||||
if (c == sc) {
|
||||
skip = true;
|
||||
continue;
|
||||
}
|
||||
if (c == cc) {
|
||||
cnt++;
|
||||
continue;
|
||||
}
|
||||
if (c == oc) {
|
||||
cnt--;
|
||||
if (cnt == 0) return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -320,7 +343,7 @@ int QCodeEdit::skipCWord(const QString & s, int pos) {
|
||||
QChar pc(0), c(0);
|
||||
for (int i = pos - 1; i >= 0; --i) {
|
||||
pc = c;
|
||||
c = s[i];
|
||||
c = s[i];
|
||||
if (c.isLetterOrNumber() || (c.toLatin1() == '_')) continue;
|
||||
if (pc.isLetter() || (pc.toLatin1() == '_')) return i + 1;
|
||||
return -1;
|
||||
@@ -339,8 +362,15 @@ bool QCodeEdit::matchWritten(QString s, QString w) {
|
||||
bool ns = false, bl = true;
|
||||
while (sp < s.size()) {
|
||||
if (ns || s[sp].toLatin1() == '_') {
|
||||
if (s[sp].toLatin1() == '_') {sp++; bl = false; continue;}
|
||||
if (s[sp].isLower() && bl) {sp++; continue;}
|
||||
if (s[sp].toLatin1() == '_') {
|
||||
sp++;
|
||||
bl = false;
|
||||
continue;
|
||||
}
|
||||
if (s[sp].isLower() && bl) {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
if (s[sp].toLower() != wc) return false;
|
||||
}
|
||||
if (s[sp].toLower() == wc) break;
|
||||
@@ -384,7 +414,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
if (!isEnabled()) {
|
||||
break;
|
||||
}
|
||||
tc = ui->textCode->cursorForPosition(static_cast<QMouseEvent*>(e)->pos());
|
||||
tc = ui->textCode->cursorForPosition(static_cast<QMouseEvent *>(e)->pos());
|
||||
tc.movePosition(QTextCursor::EndOfLine);
|
||||
pos_el_press = tc.anchor();
|
||||
tc.movePosition(QTextCursor::StartOfLine);
|
||||
@@ -397,7 +427,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
return true;
|
||||
case QEvent::MouseMove:
|
||||
if (!isEnabled()) break;
|
||||
tc = ui->textCode->cursorForPosition(static_cast<QMouseEvent*>(e)->pos());
|
||||
tc = ui->textCode->cursorForPosition(static_cast<QMouseEvent *>(e)->pos());
|
||||
tc.movePosition(QTextCursor::StartOfLine);
|
||||
if (pos_press == tc.anchor()) {
|
||||
if (!tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor)) {
|
||||
@@ -425,16 +455,15 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
if (o == completer) {
|
||||
//qDebug() << o << e;
|
||||
if (e->type() == QEvent::WindowActivate)
|
||||
_ignore_focus_out = true;
|
||||
//qDebug() << e;
|
||||
// qDebug() << o << e;
|
||||
if (e->type() == QEvent::WindowActivate) _ignore_focus_out = true;
|
||||
// qDebug() << e;
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
if (o == ui->comboSearch || o == ui->comboReplace) {
|
||||
//qDebug() << o << e;
|
||||
// qDebug() << o << e;
|
||||
if (e->type() == QEvent::KeyPress) {
|
||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
|
||||
if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Escape) {
|
||||
hideHelp();
|
||||
if (completer->isVisible())
|
||||
completer->hide();
|
||||
@@ -442,7 +471,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
hideSearch();
|
||||
}
|
||||
}
|
||||
//qDebug() << e;
|
||||
// qDebug() << e;
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
if (ui->textCode) {
|
||||
@@ -452,75 +481,62 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
cancelBlockSelection();
|
||||
completer->hide();
|
||||
hideHelp();
|
||||
auto me = static_cast<QMouseEvent*>(e);
|
||||
auto me = static_cast<QMouseEvent *>(e);
|
||||
if (me->modifiers().testFlag(Qt::ControlModifier) && (me->button() == Qt::LeftButton))
|
||||
if (!hasBlockSelection() && !ui->textCode->textCursor().hasSelection())
|
||||
gotoLink();
|
||||
} break;
|
||||
if (!hasBlockSelection() && !ui->textCode->textCursor().hasSelection()) gotoLink();
|
||||
} break;
|
||||
case QEvent::MouseMove: {
|
||||
if (!completer->isHidden()) break;
|
||||
auto me = static_cast<QMouseEvent*>(e);
|
||||
if (me->buttons() != 0)
|
||||
switchBlockSelection();
|
||||
auto me = static_cast<QMouseEvent *>(e);
|
||||
if (me->buttons() != 0) switchBlockSelection();
|
||||
if (me->modifiers().testFlag(Qt::ControlModifier))
|
||||
if (!hasBlockSelection() && !ui->textCode->textCursor().hasSelection())
|
||||
showLink();
|
||||
} break;
|
||||
case QEvent::Paint:
|
||||
resizeOverlay();
|
||||
break;
|
||||
if (!hasBlockSelection() && !ui->textCode->textCursor().hasSelection()) showLink();
|
||||
} break;
|
||||
case QEvent::Paint: resizeOverlay(); break;
|
||||
case QEvent::DragMove:
|
||||
if (!isEnabled()) break;
|
||||
drag_cursor = ui->textCode->cursorForPosition(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
static_cast<QDragMoveEvent*>(e)->pos()
|
||||
static_cast<QDragMoveEvent *>(e)->pos()
|
||||
#else
|
||||
static_cast<QDragMoveEvent*>(e)->position().toPoint()
|
||||
static_cast<QDragMoveEvent *>(e)->position().toPoint()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
repaintCursor();
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::DragLeave:
|
||||
case QEvent::Drop:
|
||||
cancelDragCursor();
|
||||
break;
|
||||
case QEvent::Drop: cancelDragCursor(); break;
|
||||
default: break;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
if (o == ui->textCode) {
|
||||
//qDebug() << e;
|
||||
// qDebug() << e;
|
||||
QMetaObject::invokeMethod(this, "syncScrolls", Qt::QueuedConnection);
|
||||
switch (e->type()) {
|
||||
case QEvent::ToolTip:
|
||||
if (completer->isHidden()) {
|
||||
QTextCursor tc = ui->textCode->cursorForPosition(static_cast<QHelpEvent*>(e)->pos());
|
||||
QTextCursor tc = ui->textCode->cursorForPosition(static_cast<QHelpEvent *>(e)->pos());
|
||||
tc.select(QTextCursor::WordUnderCursor);
|
||||
raiseHelp(tc);
|
||||
}
|
||||
break;
|
||||
case QEvent::KeyPress:
|
||||
//qDebug() << "key" << ke;
|
||||
if (codeKeyEvent(static_cast<QKeyEvent*>(e)))
|
||||
return true;
|
||||
break;
|
||||
case QEvent::KeyRelease:
|
||||
hideLink();
|
||||
// qDebug() << "key" << ke;
|
||||
if (codeKeyEvent(static_cast<QKeyEvent *>(e))) return true;
|
||||
break;
|
||||
case QEvent::KeyRelease: hideLink(); break;
|
||||
case QEvent::FocusOut:
|
||||
if (_ignore_focus_out) {
|
||||
_ignore_focus_out = false;
|
||||
break;
|
||||
}
|
||||
case QEvent::FocusIn:
|
||||
createBlockSelection();
|
||||
break;
|
||||
case QEvent::FocusIn: createBlockSelection(); break;
|
||||
case QEvent::Hide:
|
||||
case QEvent::HideToParent:
|
||||
hideLink();
|
||||
case QEvent::HideToParent: hideLink();
|
||||
case QEvent::MouseButtonPress:
|
||||
//qDebug() << e;
|
||||
// qDebug() << e;
|
||||
completer->hide();
|
||||
hideHelp();
|
||||
default: break;
|
||||
@@ -531,7 +547,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void QCodeEdit::showEvent(QShowEvent * ) {
|
||||
void QCodeEdit::showEvent(QShowEvent *) {
|
||||
if (!_first) return;
|
||||
_first = false;
|
||||
completer->installEventFilter(this);
|
||||
@@ -564,12 +580,11 @@ void QCodeEdit::leaveEvent(QEvent * e) {
|
||||
void QCodeEdit::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,7 +722,8 @@ bool QCodeEdit::codeKeyEvent(QKeyEvent * ke) {
|
||||
default: break;
|
||||
}
|
||||
if (!ke->text().isEmpty()) {
|
||||
if (hasBlockSelection() && (ke->modifiers() == 0 || ke->modifiers() == Qt::ShiftModifier || ke->modifiers() == Qt::KeypadModifier)) {
|
||||
if (hasBlockSelection() &&
|
||||
(ke->modifiers() == 0 || ke->modifiers() == Qt::ShiftModifier || ke->modifiers() == Qt::KeypadModifier)) {
|
||||
insertBlockSelection(ke->text());
|
||||
return true;
|
||||
}
|
||||
@@ -728,9 +744,9 @@ bool QCodeEdit::codeKeyEvent(QKeyEvent * ke) {
|
||||
void QCodeEdit::toggleComment() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
@@ -741,7 +757,7 @@ void QCodeEdit::toggleComment() {
|
||||
tc.movePosition(QTextCursor::StartOfLine);
|
||||
ss = tc.position();
|
||||
tc.setPosition(se);
|
||||
tc.movePosition(QTextCursor::EndOfLine );
|
||||
tc.movePosition(QTextCursor::EndOfLine);
|
||||
se = tc.position();
|
||||
tc.setPosition(ss);
|
||||
bool need_comment = false;
|
||||
@@ -754,7 +770,7 @@ void QCodeEdit::toggleComment() {
|
||||
comms[line] = true;
|
||||
} else {
|
||||
need_comment = true;
|
||||
comms[line] = false;
|
||||
comms[line] = false;
|
||||
}
|
||||
} else {
|
||||
comms[line] = false;
|
||||
@@ -816,25 +832,25 @@ void QCodeEdit::highlightBrackets() {
|
||||
QTextEdit::ExtraSelection es;
|
||||
stc.setPosition(stc.position());
|
||||
QTextCursor::MoveOperation mop[2] = {QTextCursor::Left, QTextCursor::Right};
|
||||
QString mbr[2] = {")]}>", "([{<"};
|
||||
QString mbr[2] = {")]}>", "([{<"};
|
||||
for (int d = 0; d < 2; ++d) {
|
||||
tc = stc;
|
||||
tc.movePosition(mop[d], QTextCursor::KeepAnchor);
|
||||
if (!tc.selectedText().isEmpty()) {
|
||||
char ch = tc.selectedText()[0].toLatin1();
|
||||
if (mbr[d].contains(ch)) {
|
||||
es = es_bracket;
|
||||
es = es_bracket;
|
||||
es.cursor = tc;
|
||||
es_brackets << es;
|
||||
QTextCursor ftc = tc;
|
||||
int bcnt = 1;
|
||||
char fch = antiBracket(ch);
|
||||
int bcnt = 1;
|
||||
char fch = antiBracket(ch);
|
||||
while (bcnt > 0) {
|
||||
ftc.setPosition(ftc.position());
|
||||
if (!ftc.movePosition(mop[d], QTextCursor::KeepAnchor)) break;
|
||||
//qDebug() << tc.selectedText();
|
||||
// qDebug() << tc.selectedText();
|
||||
if (ftc.selectedText().isEmpty()) break;
|
||||
if (ftc.selectedText()[0].toLatin1() == ch) ++bcnt;
|
||||
if (ftc.selectedText()[0].toLatin1() == ch) ++bcnt;
|
||||
if (ftc.selectedText()[0].toLatin1() == fch) --bcnt;
|
||||
}
|
||||
if (bcnt == 0) {
|
||||
@@ -853,9 +869,8 @@ void QCodeEdit::highlightBrackets() {
|
||||
|
||||
|
||||
void QCodeEdit::applyExtraSelection() {
|
||||
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected
|
||||
<< es_custom << es_brackets << es_search_list << es_cursor
|
||||
<< es_link << es_blockselection);
|
||||
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << es_brackets
|
||||
<< es_search_list << es_cursor << es_link << es_blockselection);
|
||||
}
|
||||
|
||||
|
||||
@@ -911,20 +926,20 @@ QRect QCodeEdit::blockSelectionRect() {
|
||||
QPoint ps(block_start_cursor.positionInBlock(), block_start_cursor.blockNumber());
|
||||
QPoint pe(tc.positionInBlock(), tc.blockNumber());
|
||||
return (ui->textCode->cursorRect(tc) | ui->textCode->cursorRect(block_start_cursor))
|
||||
.translated(ui->textCode->horizontalScrollBar()->value(), 0);
|
||||
.translated(ui->textCode->horizontalScrollBar()->value(), 0);
|
||||
}
|
||||
|
||||
|
||||
QVector<QTextCursor> QCodeEdit::blockSelectionCursors(QRect bsr) {
|
||||
QVector<QTextCursor> ret;
|
||||
//qDebug() << bsr;
|
||||
// qDebug() << bsr;
|
||||
int sline = ui->textCode->cursorForPosition(bsr.topLeft()).blockNumber();
|
||||
int eline = ui->textCode->cursorForPosition(bsr.bottomRight()).blockNumber();
|
||||
for (int l = sline; l <= eline; ++l) {
|
||||
QTextCursor stc(ui->textCode->document()->findBlockByNumber(l)), etc;
|
||||
QRect stc_rect = ui->textCode->cursorRect(stc);
|
||||
stc = ui->textCode->cursorForPosition(stc_rect.center() + QPoint(bsr.left() , 0));
|
||||
etc = ui->textCode->cursorForPosition(stc_rect.center() + QPoint(bsr.right(), 0));
|
||||
stc = ui->textCode->cursorForPosition(stc_rect.center() + QPoint(bsr.left(), 0));
|
||||
etc = ui->textCode->cursorForPosition(stc_rect.center() + QPoint(bsr.right(), 0));
|
||||
stc.setPosition(etc.position(), QTextCursor::KeepAnchor);
|
||||
ret << stc;
|
||||
}
|
||||
@@ -941,8 +956,8 @@ void QCodeEdit::drawCursor() {
|
||||
if (!isEnabled() || !ui->textCode->hasFocus()) return;
|
||||
QPainter p(overlay);
|
||||
QTextCursor tc = textCursor();
|
||||
//qDebug() << block_start_cursor.position() << tc.position();
|
||||
QRect line = cursorRect();
|
||||
// qDebug() << block_start_cursor.position() << tc.position();
|
||||
QRect line = cursorRect();
|
||||
if (cursor_state && ui->textCode->hasFocus()) {
|
||||
line.adjust(0, 1, 0, -1);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Difference);
|
||||
@@ -964,7 +979,7 @@ bool QCodeEdit::hasBlockSelection() const {
|
||||
|
||||
void QCodeEdit::startBlockSelection() {
|
||||
if (!hasBlockSelection()) {
|
||||
QTextCursor tc = textCursor();
|
||||
QTextCursor tc = textCursor();
|
||||
block_start_cursor = tc;
|
||||
block_start_cursor.setPosition(tc.selectionStart());
|
||||
}
|
||||
@@ -985,16 +1000,16 @@ void QCodeEdit::switchBlockSelection(QKeyEvent * ke) {
|
||||
}
|
||||
if (alt) {
|
||||
startBlockSelection();
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QTextCursor::MoveOperation op = QTextCursor::NoMove;
|
||||
if (!ke) {
|
||||
return;
|
||||
}
|
||||
switch (ke->key()) {
|
||||
case Qt::Key_Left : op = QTextCursor::Left ; break;
|
||||
case Qt::Key_Left: op = QTextCursor::Left; break;
|
||||
case Qt::Key_Right: op = QTextCursor::Right; break;
|
||||
case Qt::Key_Up : op = QTextCursor::Up ; break;
|
||||
case Qt::Key_Down : op = QTextCursor::Down ; break;
|
||||
case Qt::Key_Up: op = QTextCursor::Up; break;
|
||||
case Qt::Key_Down: op = QTextCursor::Down; break;
|
||||
default: break;
|
||||
}
|
||||
if (op != QTextCursor::NoMove) {
|
||||
@@ -1013,7 +1028,7 @@ bool QCodeEdit::removeBlockSelection(bool is_del) {
|
||||
return false;
|
||||
}
|
||||
QRect bsr = blockSelectionRect();
|
||||
bool del = false;
|
||||
bool del = false;
|
||||
bool back = false;
|
||||
if (bsr.width() <= 1) {
|
||||
if (is_del) {
|
||||
@@ -1023,19 +1038,19 @@ bool QCodeEdit::removeBlockSelection(bool is_del) {
|
||||
}
|
||||
}
|
||||
QVector<QTextCursor> clist = blockSelectionCursors(bsr);
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int bspx = ui->textCode->cursorRect(block_start_cursor).center().x();
|
||||
int bspx = ui->textCode->cursorRect(block_start_cursor).center().x();
|
||||
int nullw = ui->textCode->fontMetrics().
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
horizontalAdvance
|
||||
horizontalAdvance
|
||||
#else
|
||||
width
|
||||
width
|
||||
#endif
|
||||
(" ");
|
||||
(" ");
|
||||
int min_dist = nullw / 2;
|
||||
int new_pos = -1;
|
||||
for (QTextCursor & c : clist) {
|
||||
int new_pos = -1;
|
||||
for (QTextCursor & c: clist) {
|
||||
if (del || back) {
|
||||
if (qAbs(bspx - ui->textCode->cursorRect(c).center().x()) > min_dist) {
|
||||
continue;
|
||||
@@ -1045,7 +1060,7 @@ bool QCodeEdit::removeBlockSelection(bool is_del) {
|
||||
if (line != c.blockNumber()) {
|
||||
continue;
|
||||
}
|
||||
//qDebug() << qAbs(bspx - ui->textCode->cursorRect(c).center().x()) << min_dist;
|
||||
// qDebug() << qAbs(bspx - ui->textCode->cursorRect(c).center().x()) << min_dist;
|
||||
}
|
||||
c.removeSelectedText();
|
||||
if (c.blockNumber() == tc.blockNumber()) {
|
||||
@@ -1064,24 +1079,24 @@ void QCodeEdit::insertBlockSelection(QString text) {
|
||||
return;
|
||||
}
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QRect bsr = blockSelectionRect();
|
||||
//qDebug() << "___" << bsr;
|
||||
int scrl = ui->textCode->horizontalScrollBar()->value();
|
||||
QRect bsr = blockSelectionRect();
|
||||
// qDebug() << "___" << bsr;
|
||||
int scrl = ui->textCode->horizontalScrollBar()->value();
|
||||
if (bsr.width() > 1) {
|
||||
removeBlockSelection(false);
|
||||
bsr = blockSelectionRect();
|
||||
//qDebug() << "del" << bsr;
|
||||
// qDebug() << "del" << bsr;
|
||||
}
|
||||
tc.beginEditBlock();
|
||||
int nullw = ui->textCode->fontMetrics().
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
horizontalAdvance
|
||||
horizontalAdvance
|
||||
#else
|
||||
width
|
||||
width
|
||||
#endif
|
||||
(" ");
|
||||
(" ");
|
||||
QVector<QTextCursor> clist = blockSelectionCursors(bsr);
|
||||
for (QTextCursor & c : clist) {
|
||||
for (QTextCursor & c: clist) {
|
||||
c.removeSelectedText();
|
||||
int spcnt = (bsr.left() - ui->textCode->cursorRect(c).center().x() - scrl) / nullw;
|
||||
if (spcnt > 0) {
|
||||
@@ -1102,7 +1117,7 @@ void QCodeEdit::createBlockSelection() {
|
||||
es.format.setForeground(palette().brush(QPalette::HighlightedText));
|
||||
es.format.setBackground(palette().brush(QPalette::Highlight));
|
||||
QVector<QTextCursor> clist = blockSelectionCursors(blockSelectionRect());
|
||||
for (QTextCursor & c : clist) {
|
||||
for (QTextCursor & c: clist) {
|
||||
es.cursor = c;
|
||||
es_blockselection << es;
|
||||
}
|
||||
@@ -1145,7 +1160,7 @@ void QCodeEdit::searchAll() {
|
||||
|
||||
void QCodeEdit::search_triggered() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QString st = tc.selectedText();
|
||||
QString st = tc.selectedText();
|
||||
if (st.isEmpty()) {
|
||||
tc.select(QTextCursor::WordUnderCursor);
|
||||
st = tc.selectedText();
|
||||
@@ -1159,7 +1174,8 @@ void QCodeEdit::search_triggered() {
|
||||
|
||||
void QCodeEdit::syncScrolls() {
|
||||
ui->textLines->verticalScrollBar()->setValue(ui->textCode->verticalScrollBar()->value());
|
||||
ui->textLines->setHorizontalScrollBarPolicy(ui->textCode->horizontalScrollBar()->isVisible() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff);
|
||||
ui->textLines->setHorizontalScrollBarPolicy(ui->textCode->horizontalScrollBar()->isVisible() ? Qt::ScrollBarAlwaysOn
|
||||
: Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
|
||||
|
||||
@@ -1196,9 +1212,9 @@ void QCodeEdit::deleteLine() {
|
||||
void QCodeEdit::copyLineUp() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
@@ -1237,9 +1253,9 @@ void QCodeEdit::copyLineUp() {
|
||||
void QCodeEdit::copyLineDown() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
@@ -1281,10 +1297,10 @@ void QCodeEdit::copyLineDown() {
|
||||
|
||||
void QCodeEdit::moveLineUp() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
se--;
|
||||
@@ -1333,10 +1349,10 @@ void QCodeEdit::moveLineUp() {
|
||||
|
||||
void QCodeEdit::moveLineDown() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
se--;
|
||||
@@ -1387,9 +1403,9 @@ void QCodeEdit::moveLineDown() {
|
||||
void QCodeEdit::indent() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
@@ -1421,9 +1437,9 @@ void QCodeEdit::indent() {
|
||||
void QCodeEdit::deindent() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
tc.beginEditBlock();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
int ss = tc.selectionStart();
|
||||
int ss_ = ss;
|
||||
int se = tc.selectionEnd();
|
||||
QString st_ = tc.selection().toPlainText();
|
||||
if (st_.endsWith("\n")) {
|
||||
st_.chop(1);
|
||||
@@ -1461,8 +1477,7 @@ void QCodeEdit::deindent() {
|
||||
}
|
||||
se_ -= rs;
|
||||
tc.movePosition(QTextCursor::StartOfLine);
|
||||
if (!tc.movePosition(QTextCursor::Down))
|
||||
break;
|
||||
if (!tc.movePosition(QTextCursor::Down)) break;
|
||||
}
|
||||
tc.setPosition(ss_);
|
||||
tc.setPosition(se_, QTextCursor::KeepAnchor);
|
||||
@@ -1472,7 +1487,7 @@ void QCodeEdit::deindent() {
|
||||
|
||||
|
||||
void QCodeEdit::autoIndent() {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
QTextCursor stc = tc;
|
||||
tc.movePosition(QTextCursor::StartOfLine);
|
||||
if (!tc.movePosition(QTextCursor::Up)) {
|
||||
@@ -1517,7 +1532,7 @@ void QCodeEdit::showLink() {
|
||||
es_link.cursor = tc;
|
||||
overlay->setCursor(tc.isNull() ? Qt::IBeamCursor : Qt::PointingHandCursor);
|
||||
applyExtraSelection();
|
||||
//qDebug() << "showLink" << tc.selectedText() << link_entry.type << link_entry.name;
|
||||
// qDebug() << "showLink" << tc.selectedText() << link_entry.type << link_entry.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1526,7 +1541,7 @@ void QCodeEdit::hideLink() {
|
||||
overlay->setCursor(Qt::IBeamCursor);
|
||||
link_entry = ACEntry();
|
||||
applyExtraSelection();
|
||||
//qDebug() << "hideLink";
|
||||
// qDebug() << "hideLink";
|
||||
}
|
||||
|
||||
|
||||
@@ -1619,7 +1634,7 @@ QString QCodeEdit::selectArg(QString s, int arg) {
|
||||
s.chop(1);
|
||||
}
|
||||
QStringList al = s.split(",");
|
||||
QString ret = ss + "(";
|
||||
QString ret = ss + "(";
|
||||
for (int i = 0; i < al.size(); ++i) {
|
||||
if (i > 0) {
|
||||
ret += ", ";
|
||||
@@ -1638,7 +1653,7 @@ QString QCodeEdit::selectArg(QString s, int arg) {
|
||||
|
||||
|
||||
QCodeEdit::ACEntry QCodeEdit::findEntryOnCursor(QTextCursor tc, int arg, ACClass * acc, QPair<QStringList, QString> * scope) {
|
||||
bool ok = false;
|
||||
bool ok = false;
|
||||
QPair<QStringList, QString> sc = getScope(tc, &ok);
|
||||
if (scope) {
|
||||
*scope = sc;
|
||||
@@ -1652,10 +1667,10 @@ QCodeEdit::ACEntry QCodeEdit::findEntryOnCursor(QTextCursor tc, int arg, ACClass
|
||||
}
|
||||
ok = false;
|
||||
ACList acl(autoCompletitionList(sc.first, sc.second));
|
||||
for (const ACSection & i : acl) {
|
||||
for (const ACEntry & s : i.second) {
|
||||
for (const ACSection & i: acl) {
|
||||
for (const ACEntry & s: i.second) {
|
||||
QString ts = s.name;
|
||||
//qDebug() << ts << st;
|
||||
// qDebug() << ts << st;
|
||||
if (ts != st) {
|
||||
if (ts.startsWith(st)) {
|
||||
ts.remove(0, st.size());
|
||||
@@ -1669,7 +1684,7 @@ QCodeEdit::ACEntry QCodeEdit::findEntryOnCursor(QTextCursor tc, int arg, ACClass
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//qDebug() << s.second << st;
|
||||
// qDebug() << s.second << st;
|
||||
if (acc) {
|
||||
*acc = ac_classes.value(i.first);
|
||||
}
|
||||
@@ -1696,10 +1711,10 @@ void QCodeEdit::raiseHelp(QTextCursor tc, int arg) {
|
||||
}
|
||||
lbl_help[lhHint]->setText(hint);
|
||||
lbl_help[lhHint]->setHidden(hint.isEmpty());
|
||||
//qDebug() << "help found" << tc.selectionStart() << tc.selectionEnd();
|
||||
// qDebug() << "help found" << tc.selectionStart() << tc.selectionEnd();
|
||||
es_cursor.cursor = tc;
|
||||
applyExtraSelection();
|
||||
//tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
|
||||
// tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
|
||||
lbl_help[lhMain]->setFont(font());
|
||||
lbl_help[lhF1]->setVisible(!e.help_href.isEmpty() && help_visible);
|
||||
qApp->processEvents();
|
||||
@@ -1715,14 +1730,14 @@ void QCodeEdit::raiseHelp(QTextCursor tc, int arg) {
|
||||
QPoint whp;
|
||||
whp.setX(whr.left() - whr.width() - (widget_help->width() - whr.width()) / 2);
|
||||
whp.setY(whr.top() - widget_help->height() - (fontHeight(this) / 3));
|
||||
//qDebug() << whr << whp << widget_help->width() << ", " << st;
|
||||
// qDebug() << whr << whp << widget_help->width() << ", " << st;
|
||||
widget_help->move(ui->textCode->viewport()->mapToGlobal(whp));
|
||||
widget_help->show();
|
||||
widget_help->raise();
|
||||
help_entry = e;
|
||||
help_entry = e;
|
||||
cursor_scope = scope.first;
|
||||
cursor_scope << scope.second;
|
||||
//qDebug() << "tooltip" << st;
|
||||
// qDebug() << "tooltip" << st;
|
||||
}
|
||||
|
||||
|
||||
@@ -1774,7 +1789,7 @@ QTextCursor QCodeEdit::functionStart(QTextCursor tc, int * arg) {
|
||||
}
|
||||
QTextCursor ret(ui->textCode->document());
|
||||
ret.setPosition(i);
|
||||
//qDebug() << "found" << i << a;
|
||||
// qDebug() << "found" << i << a;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1801,7 +1816,7 @@ QCodeEdit::ACList QCodeEdit::wordsCompletitionList(const QString & written) cons
|
||||
acwl.removeDuplicates();
|
||||
ACSection acl;
|
||||
acl.first = -1;
|
||||
for (const QString & s : acwl) {
|
||||
for (const QString & s: acwl) {
|
||||
acl.second << ACEntry("", s);
|
||||
}
|
||||
ret << acl;
|
||||
@@ -1831,14 +1846,14 @@ QPair<QStringList, QString> QCodeEdit::getScope(QTextCursor tc, bool * ok) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
QString doc = ui->textCode->toPlainText();
|
||||
QString doc = ui->textCode->toPlainText();
|
||||
auto_comp_pl = line;
|
||||
completer->clear();
|
||||
int spos = tc.position(), cpos = spos;
|
||||
tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
|
||||
QStringList scope;
|
||||
QString written = tc.selectedText().trimmed();
|
||||
//qDebug() << "\n*** invokeAutoCompletition ***";
|
||||
// qDebug() << "\n*** invokeAutoCompletition ***";
|
||||
if (written != "_" && !written.leftJustified(1)[0].isLetterOrNumber()) {
|
||||
written.clear();
|
||||
} else {
|
||||
@@ -1849,13 +1864,13 @@ QPair<QStringList, QString> QCodeEdit::getScope(QTextCursor tc, bool * ok) {
|
||||
}
|
||||
while (cpos >= 0) {
|
||||
cpos--;
|
||||
//qDebug() << "char =" << doc.mid(cpos, 1);
|
||||
// qDebug() << "char =" << doc.mid(cpos, 1);
|
||||
if (doc.mid(cpos, 1) != ".") break;
|
||||
QChar c = doc.mid(cpos - 1, 1).leftJustified(1)[0];
|
||||
QChar c = doc.mid(cpos - 1, 1).leftJustified(1)[0];
|
||||
int ppos = cpos;
|
||||
if (c == '\"' || c == ')' || c == ']') {
|
||||
cpos = skipRange(doc, cpos, pairChar(c), c, '\\');
|
||||
//qDebug() << "range" << cpos;
|
||||
// qDebug() << "range" << cpos;
|
||||
if (cpos < 0) break;
|
||||
}
|
||||
int npos = skipCWord(doc, cpos);
|
||||
@@ -1863,7 +1878,7 @@ QPair<QStringList, QString> QCodeEdit::getScope(QTextCursor tc, bool * ok) {
|
||||
scope.push_front(doc.mid(npos, ppos - npos));
|
||||
cpos = npos;
|
||||
}
|
||||
ret.first = scope;
|
||||
ret.first = scope;
|
||||
ret.second = written;
|
||||
if (ok) *ok = true;
|
||||
return ret;
|
||||
@@ -1871,17 +1886,17 @@ QPair<QStringList, QString> QCodeEdit::getScope(QTextCursor tc, bool * ok) {
|
||||
|
||||
|
||||
void QCodeEdit::invokeAutoCompletition(bool force) {
|
||||
int arg = -1;
|
||||
int arg = -1;
|
||||
QTextCursor htc = functionStart(ui->textCode->textCursor(), &arg);
|
||||
if (!htc.isNull()) {
|
||||
//qDebug() << "raise";
|
||||
// qDebug() << "raise";
|
||||
raiseHelp(htc, arg);
|
||||
}
|
||||
bool ok;
|
||||
QPair<QStringList, QString> scope = getScope(ui->textCode->textCursor(), &ok);
|
||||
if (!ok) return;
|
||||
ACList acl(autoCompletitionList(scope.first, scope.second));
|
||||
//qDebug() << written << scope << acl.size();
|
||||
// qDebug() << written << scope << acl.size();
|
||||
if (scope.first.isEmpty() && scope.second.isEmpty() && !force) {
|
||||
completer->hide();
|
||||
hideHelp();
|
||||
@@ -1892,7 +1907,7 @@ void QCodeEdit::invokeAutoCompletition(bool force) {
|
||||
}
|
||||
QFont bf(font());
|
||||
bf.setBold(true);
|
||||
foreach (const ACSection & ac, acl) {
|
||||
foreach(const ACSection & ac, acl) {
|
||||
if (ac.second.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -1970,7 +1985,7 @@ void QCodeEdit::commitCompletition() {
|
||||
|
||||
void QCodeEdit::textEdit_cursorPositionChanged() {
|
||||
es_line.cursor = ui->textCode->textCursor();
|
||||
//qDebug() << "cursorPositionChanged" << es_line.cursor.position();
|
||||
// qDebug() << "cursorPositionChanged" << es_line.cursor.position();
|
||||
es_line.cursor.select(QTextCursor::LineUnderCursor);
|
||||
es_line.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
|
||||
highlightBrackets();
|
||||
@@ -1978,7 +1993,7 @@ void QCodeEdit::textEdit_cursorPositionChanged() {
|
||||
if (timer_blink) {
|
||||
killTimer(timer_blink);
|
||||
}
|
||||
timer_blink = startTimer(QApplication::cursorFlashTime() / 2);
|
||||
timer_blink = startTimer(QApplication::cursorFlashTime() / 2);
|
||||
cursor_state = true;
|
||||
createBlockSelection();
|
||||
}
|
||||
@@ -1996,8 +2011,8 @@ void QCodeEdit::textEdit_textChanged() {
|
||||
void QCodeEdit::textEdit_selectionChanged() {
|
||||
if (hasBlockSelection()) {
|
||||
QTextCursor tc = ui->textCode->textCursor();
|
||||
//qDebug() << block_start_cursor.selectionStart() << tc.selectionEnd();
|
||||
bool bs = ui->textCode->blockSignals(true);
|
||||
// qDebug() << block_start_cursor.selectionStart() << tc.selectionEnd();
|
||||
bool bs = ui->textCode->blockSignals(true);
|
||||
tc.clearSelection();
|
||||
ui->textCode->setTextCursor(tc);
|
||||
ui->textCode->blockSignals(bs);
|
||||
@@ -2032,8 +2047,8 @@ void QCodeEdit::textEdit_redoAvailable(bool available) {
|
||||
|
||||
|
||||
void QCodeEdit::setShowSpaces(bool yes) {
|
||||
spaces_ = yes;
|
||||
QTextOption to = ui->textCode->document()->defaultTextOption();
|
||||
spaces_ = yes;
|
||||
QTextOption to = ui->textCode->document()->defaultTextOption();
|
||||
QTextOption::Flags tof = to.flags();
|
||||
if (yes) {
|
||||
tof |= QTextOption::ShowTabsAndSpaces;
|
||||
@@ -2122,8 +2137,6 @@ void QCodeEdit::on_buttonReplaceAll_clicked() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QString QCodeEdit::ACEntry::declaration() const {
|
||||
if (declaration_pos < 0 || declaration_file.isEmpty()) {
|
||||
return QString();
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QCODEEDIT_H
|
||||
#define QCODEEDIT_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QTextEdit>
|
||||
#include <QUrl>
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class QCodeEdit;
|
||||
class QCodeEdit;
|
||||
}
|
||||
|
||||
class QPlainTextEdit;
|
||||
@@ -36,8 +37,7 @@ class IconedLabel;
|
||||
class _QCE_Viewport;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool showSpaces READ showSpaces WRITE setShowSpaces)
|
||||
@@ -47,24 +47,34 @@ class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget
|
||||
|
||||
friend class QCodeEditCompleter;
|
||||
friend class _QCE_Viewport;
|
||||
|
||||
|
||||
public:
|
||||
QCodeEdit(QWidget * parent = nullptr);
|
||||
~QCodeEdit() override;
|
||||
|
||||
|
||||
enum ACClassType {
|
||||
Keyword,
|
||||
Function,
|
||||
Namespace
|
||||
};
|
||||
struct QAD_WIDGETS_EXPORT ACEntry {
|
||||
ACEntry(const QString & t = QString(), const QString & n = QString(), const QString & h = QString()):
|
||||
type(t), name(n), hint(h) {declaration_pos = -1;}
|
||||
bool isNull() const {return type.isEmpty() && name.isEmpty();}
|
||||
ACEntry(const QString & t = QString(), const QString & n = QString(), const QString & h = QString()): type(t), name(n), hint(h) {
|
||||
declaration_pos = -1;
|
||||
}
|
||||
bool isNull() const { return type.isEmpty() && name.isEmpty(); }
|
||||
QString declaration() const;
|
||||
ACEntry & addHint(QString h) {hint = h; return *this;}
|
||||
ACEntry & addHelpHRef(QUrl h) {help_href = h; return *this;}
|
||||
ACEntry & addCustomData(QVariant d) {custom_data = d; return *this;}
|
||||
ACEntry & addHint(QString h) {
|
||||
hint = h;
|
||||
return *this;
|
||||
}
|
||||
ACEntry & addHelpHRef(QUrl h) {
|
||||
help_href = h;
|
||||
return *this;
|
||||
}
|
||||
ACEntry & addCustomData(QVariant d) {
|
||||
custom_data = d;
|
||||
return *this;
|
||||
}
|
||||
QString type;
|
||||
QString name;
|
||||
QString hint;
|
||||
@@ -86,7 +96,7 @@ public:
|
||||
QRect cursorRect(const QTextCursor & cursor) const;
|
||||
QString text() const;
|
||||
QStringList cursorScope() const;
|
||||
bool showSpaces() const {return spaces_;}
|
||||
bool showSpaces() const { return spaces_; }
|
||||
bool showLineNumbers() const;
|
||||
void setHelpHintVisible(bool on);
|
||||
bool isHelpHintVisible() const;
|
||||
@@ -95,23 +105,23 @@ public:
|
||||
|
||||
void setEditorFont(QFont f);
|
||||
QFont editorFont() const;
|
||||
|
||||
|
||||
QPlainTextEdit * textEdit() const;
|
||||
|
||||
|
||||
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
|
||||
bool wordCompletitionEnabled() const {return word_complete;}
|
||||
bool wordCompletitionEnabled() const { return word_complete; }
|
||||
|
||||
protected:
|
||||
typedef QPair<QString, QString> StringsPair;
|
||||
typedef QPair<int, QList<ACEntry> > ACSection; // section, ACClass.id -> list of entries
|
||||
typedef QList<ACSection> ACList; // list of sections
|
||||
|
||||
virtual ACList autoCompletitionList(const QStringList & scope, const QString & written) const {return ACList();}
|
||||
typedef QPair<int, QList<ACEntry>> ACSection; // section, ACClass.id -> list of entries
|
||||
typedef QList<ACSection> ACList; // list of sections
|
||||
|
||||
virtual ACList autoCompletitionList(const QStringList & scope, const QString & written) const { return ACList(); }
|
||||
virtual void parse() {}
|
||||
virtual void documentUnset() {}
|
||||
virtual void documentChanged(QTextDocument * d) {}
|
||||
virtual void linkClicked(ACEntry entry) {}
|
||||
virtual bool linkValidate(ACEntry e) {return true;}
|
||||
virtual bool linkValidate(ACEntry e) { return true; }
|
||||
|
||||
QString selectArg(QString s, int arg);
|
||||
void raiseHelp(QTextCursor tc, int arg = -1);
|
||||
@@ -124,7 +134,7 @@ protected:
|
||||
static QChar pairChar(QChar c);
|
||||
|
||||
private slots:
|
||||
void _activateLink(QCodeEdit::ACEntry e) {linkClicked(e);}
|
||||
void _activateLink(QCodeEdit::ACEntry e) { linkClicked(e); }
|
||||
void gotoHelpHRef(QCodeEdit::ACEntry e);
|
||||
void resizeOverlay();
|
||||
void syncScrolls();
|
||||
@@ -166,18 +176,22 @@ public slots:
|
||||
void setShowLineNumbers(bool yes);
|
||||
void search(const QString & t);
|
||||
void searchNext(bool next);
|
||||
void searchNext() {searchNext(true);}
|
||||
void searchNext() { searchNext(true); }
|
||||
void searchPrevious();
|
||||
void hideSearch();
|
||||
void setWordCompletitionEnabled(bool on) {word_complete = on;}
|
||||
void setWordCompletitionEnabled(bool on) { word_complete = on; }
|
||||
|
||||
signals:
|
||||
void textChanged();
|
||||
void parseRequest();
|
||||
|
||||
|
||||
private:
|
||||
struct QAD_WIDGETS_EXPORT ACClass {
|
||||
ACClass(int i = -2, ACClassType c = QCodeEdit::Keyword, const QString & n = QString(), const QIcon & ic = QIcon()): id(i), class_(c), name(n), icon(ic) {}
|
||||
ACClass(int i = -2, ACClassType c = QCodeEdit::Keyword, const QString & n = QString(), const QIcon & ic = QIcon())
|
||||
: id(i)
|
||||
, class_(c)
|
||||
, name(n)
|
||||
, icon(ic) {}
|
||||
int id;
|
||||
ACClassType class_;
|
||||
QString name;
|
||||
@@ -191,9 +205,9 @@ private:
|
||||
};
|
||||
|
||||
bool eventFilter(QObject * o, QEvent * e) override;
|
||||
void showEvent(QShowEvent * ) override;
|
||||
void timerEvent(QTimerEvent * ) override;
|
||||
void leaveEvent(QEvent * ) override;
|
||||
void showEvent(QShowEvent *) override;
|
||||
void timerEvent(QTimerEvent *) override;
|
||||
void leaveEvent(QEvent *) override;
|
||||
void changeEvent(QEvent * e) override;
|
||||
bool codeKeyEvent(QKeyEvent * ke);
|
||||
void toggleComment();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "qcodeedit_completer_p.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
|
||||
|
||||
QCodeEditCompleter::QCodeEditCompleter(QWidget * parent): QTreeWidget(parent) {
|
||||
@@ -17,17 +19,16 @@ QCodeEditCompleter::QCodeEditCompleter(QWidget * parent): QTreeWidget(parent) {
|
||||
header()->setDefaultAlignment(Qt::AlignCenter);
|
||||
header()->
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
setSectionResizeMode
|
||||
setSectionResizeMode
|
||||
#else
|
||||
setResizeMode
|
||||
setResizeMode
|
||||
#endif
|
||||
(QHeaderView::ResizeToContents);
|
||||
(QHeaderView::ResizeToContents);
|
||||
header()->setStretchLastSection(false);
|
||||
}
|
||||
|
||||
|
||||
QCodeEditCompleter::~QCodeEditCompleter() {
|
||||
}
|
||||
QCodeEditCompleter::~QCodeEditCompleter() {}
|
||||
|
||||
|
||||
void QCodeEditCompleter::nextCompletition() {
|
||||
@@ -63,7 +64,7 @@ void QCodeEditCompleter::addItems(QFont f, const QCodeEdit::ACClass & cl, const
|
||||
gi->setFlags(Qt::ItemIsEnabled);
|
||||
addTopLevelItem(gi);
|
||||
gi->setFirstColumnSpanned(true);
|
||||
foreach (const auto & s, items.second) {
|
||||
foreach(const auto & s, items.second) {
|
||||
QTreeWidgetItem * ni = new QTreeWidgetItem();
|
||||
ni->setIcon(0, cl.icon);
|
||||
ni->setText(0, s.type);
|
||||
@@ -74,7 +75,6 @@ void QCodeEditCompleter::addItems(QFont f, const QCodeEdit::ACClass & cl, const
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QCodeEditCompleter::invoke(QPoint global_pos) {
|
||||
setCurrentItem(topLevelItem(1));
|
||||
if (isHidden()) move(global_pos);
|
||||
@@ -101,12 +101,8 @@ QString QCodeEditCompleter::currentValue() const {
|
||||
|
||||
void QCodeEditCompleter::keyPressEvent(QKeyEvent * e) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Escape:
|
||||
hide();
|
||||
break;
|
||||
case Qt::Key_Return:
|
||||
emit commit();
|
||||
break;
|
||||
case Qt::Key_Escape: hide(); break;
|
||||
case Qt::Key_Return: emit commit(); break;
|
||||
case Qt::Key_F1:
|
||||
if (currentItem()) {
|
||||
QString href = currentItem()->data(0, Qt::UserRole).toString();
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QCODEEDIT_COMPLETER_P_H
|
||||
#define QCODEEDIT_COMPLETER_P_H
|
||||
|
||||
#include "qcodeedit.h"
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
|
||||
class QCodeEditCompleter: public QTreeWidget
|
||||
{
|
||||
class QCodeEditCompleter: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QCodeEditCompleter(QWidget * parent = nullptr);
|
||||
~QCodeEditCompleter() override;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "qipedit.h"
|
||||
|
||||
#include "qalgorithms.h"
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QIntValidator>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
|
||||
QIPEdit::QIPEdit(QWidget * parent, const QString & ip): QWidget(parent) {
|
||||
@@ -44,10 +46,10 @@ void QIPEdit::setIP(const QString & text) {
|
||||
s = str.left(str.indexOf('.'));
|
||||
edits[0]->setText(s == "" ? "0" : s);
|
||||
str = str.right(str.length() - s.length() - 1);
|
||||
s = str.left(str.indexOf('.'));
|
||||
s = str.left(str.indexOf('.'));
|
||||
edits[1]->setText(s == "" ? "0" : s);
|
||||
str = str.right(str.length() - s.length() - 1);
|
||||
s = str.left(str.indexOf('.'));
|
||||
s = str.left(str.indexOf('.'));
|
||||
edits[2]->setText(s == "" ? "0" : s);
|
||||
str = str.right(str.length() - s.length() - 1);
|
||||
edits[3]->setText(str == "" ? "0" : str);
|
||||
@@ -56,14 +58,22 @@ void QIPEdit::setIP(const QString & text) {
|
||||
|
||||
QString QIPEdit::IP() {
|
||||
QString s;
|
||||
if (edits[0]->text() == "") s = "0.";
|
||||
else s = edits[0]->text() + ".";
|
||||
if (edits[1]->text() == "") s += "0.";
|
||||
else s += edits[1]->text() + ".";
|
||||
if (edits[2]->text() == "") s += "0.";
|
||||
else s += edits[2]->text() + ".";
|
||||
if (edits[3]->text() == "") s += "0";
|
||||
else s += edits[3]->text();
|
||||
if (edits[0]->text() == "")
|
||||
s = "0.";
|
||||
else
|
||||
s = edits[0]->text() + ".";
|
||||
if (edits[1]->text() == "")
|
||||
s += "0.";
|
||||
else
|
||||
s += edits[1]->text() + ".";
|
||||
if (edits[2]->text() == "")
|
||||
s += "0.";
|
||||
else
|
||||
s += edits[2]->text() + ".";
|
||||
if (edits[3]->text() == "")
|
||||
s += "0";
|
||||
else
|
||||
s += edits[3]->text();
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -76,7 +86,7 @@ void QIPEdit::returnPress(int index) {
|
||||
}
|
||||
|
||||
|
||||
inline void QIPEdit::textChange(int index, const QString &text) {
|
||||
inline void QIPEdit::textChange(int index, const QString & text) {
|
||||
if (text.length() == 3 && isVisible()) {
|
||||
returnPress(index);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QIPEDIT_H
|
||||
#define QIPEDIT_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
@@ -29,40 +30,39 @@ class QLineEdit;
|
||||
class QLabel;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QIPEdit: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT QIPEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString IP READ IP WRITE setIP)
|
||||
|
||||
|
||||
public:
|
||||
QIPEdit(QWidget * parent = nullptr, const QString & ip = "");
|
||||
|
||||
|
||||
QString IP();
|
||||
|
||||
|
||||
public slots:
|
||||
void setIP(const QString & text);
|
||||
|
||||
|
||||
private slots:
|
||||
void returnPressed0() {returnPress(0);}
|
||||
void returnPressed1() {returnPress(1);}
|
||||
void returnPressed2() {returnPress(2);}
|
||||
void returnPressed3() {returnPress(3);}
|
||||
void textChanged0(const QString & text) {textChange(0, text);}
|
||||
void textChanged1(const QString & text) {textChange(1, text);}
|
||||
void textChanged2(const QString & text) {textChange(2, text);}
|
||||
void textChanged3(const QString & text) {textChange(3, text);}
|
||||
|
||||
void returnPressed0() { returnPress(0); }
|
||||
void returnPressed1() { returnPress(1); }
|
||||
void returnPressed2() { returnPress(2); }
|
||||
void returnPressed3() { returnPress(3); }
|
||||
void textChanged0(const QString & text) { textChange(0, text); }
|
||||
void textChanged1(const QString & text) { textChange(1, text); }
|
||||
void textChanged2(const QString & text) { textChange(2, text); }
|
||||
void textChanged3(const QString & text) { textChange(3, text); }
|
||||
|
||||
signals:
|
||||
void valueChanged(QString);
|
||||
|
||||
private:
|
||||
void returnPress(int index);
|
||||
void textChange(int index, const QString &text);
|
||||
void textChange(int index, const QString & text);
|
||||
|
||||
int cind;
|
||||
QBoxLayout * layout;
|
||||
QList<QLineEdit * > edits;
|
||||
QList<QLabel * > dots;
|
||||
QList<QLineEdit *> edits;
|
||||
QList<QLabel *> dots;
|
||||
};
|
||||
|
||||
#endif // QIPEDIT_H
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "qpiconfignewdialog.h"
|
||||
|
||||
#include "ui_qpiconfignewdialog.h"
|
||||
|
||||
|
||||
QPIConfigNewDialog::QPIConfigNewDialog(QWidget * parent): QDialog(parent) {
|
||||
ui = new Ui::QPIConfigNewDialog();
|
||||
ui->setupUi(this);
|
||||
radios = findChildren<QRadioButton * >();
|
||||
radios = findChildren<QRadioButton *>();
|
||||
ui->widgetValue->hideAll();
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
@@ -14,17 +15,14 @@ QPIConfigNewDialog::QPIConfigNewDialog(QWidget * parent): QDialog(parent) {
|
||||
void QPIConfigNewDialog::changeEvent(QEvent * e) {
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigNewDialog::typeChanged() {
|
||||
for (const QRadioButton * i : radios) {
|
||||
for (const QRadioButton * i: radios) {
|
||||
if (i->isChecked()) {
|
||||
ui->widgetValue->setType(i->property("type").toString());
|
||||
return;
|
||||
@@ -34,7 +32,7 @@ void QPIConfigNewDialog::typeChanged() {
|
||||
|
||||
|
||||
QString QPIConfigNewDialog::type() {
|
||||
for (const QRadioButton * i : radios) {
|
||||
for (const QRadioButton * i: radios) {
|
||||
if (i->isChecked()) {
|
||||
return i->property("type").toString();
|
||||
}
|
||||
|
||||
@@ -1,60 +1,59 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPICONFIGNEWDIALOG_H
|
||||
#define QPICONFIGNEWDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class QPIConfigNewDialog;
|
||||
class QPIConfigNewDialog;
|
||||
}
|
||||
|
||||
class QRadioButton;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QPIConfigNewDialog: public QDialog
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT QPIConfigNewDialog: public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
QPIConfigNewDialog(QWidget * parent = nullptr);
|
||||
|
||||
|
||||
QString type();
|
||||
QString name();
|
||||
QString value();
|
||||
QString comment();
|
||||
void reset(bool node = false);
|
||||
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e) override;
|
||||
|
||||
|
||||
private slots:
|
||||
void on_lineName_textChanged(const QString & text);
|
||||
void typeChanged();
|
||||
|
||||
private:
|
||||
Ui::QPIConfigNewDialog * ui;
|
||||
QList<QRadioButton * > radios;
|
||||
|
||||
QList<QRadioButton *> radios;
|
||||
};
|
||||
|
||||
#endif // QPICONFIGNEWDIALOG_H
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "qpiconfigvaluewidget.h"
|
||||
|
||||
#include "qpievaluator_p.h"
|
||||
|
||||
|
||||
@@ -35,44 +36,175 @@ ConfigValueWidget::ConfigValueWidget(QWidget * parent): QWidget(parent), lay(QBo
|
||||
|
||||
void ConfigValueWidget::setType(const QString & t) {
|
||||
hideAll();
|
||||
type = t.left(1);
|
||||
type = t.left(1);
|
||||
active = false;
|
||||
if (type == "e") {QStringList en_sl = QPIEvaluator::inBrackets(comment).split(';');
|
||||
if (en_sl.size()>1) {
|
||||
w_enum.show(); w_enum.addItems(en_sl); setValue(value); active = true; return;
|
||||
} else {type = "s";}}
|
||||
if (type == "s") {w_string.show(); setValue(value); active = true; return;}
|
||||
if (type == "l") {w_list.show(); setValue(value); active = true; return;}
|
||||
if (type == "b") {w_bool.show(); setValue(value); active = true; return;}
|
||||
if (type == "n") {w_integer.show(); setValue(value); active = true; return;}
|
||||
if (type == "f") {w_float.show(); setValue(value); active = true; return;}
|
||||
if (type == "c") {w_color.show(); setValue(value); active = true; return;}
|
||||
if (type == "r") {w_rect.show(); w_rect.setDecimals(0); setValue(value); active = true; return;}
|
||||
if (type == "a") {w_rect.show(); w_rect.setDecimals(3); setValue(value); active = true; return;}
|
||||
if (type == "p") {w_point.show(); w_point.setDecimals(0); setValue(value); active = true; return;}
|
||||
if (type == "v") {w_point.show(); w_point.setDecimals(3); setValue(value); active = true; return;}
|
||||
if (type == "i") {w_ip.show(); setValue(value); active = true; return;}
|
||||
if (type == "F") {w_path.show(); setValue(value); active = true; return;}
|
||||
if (type == "D") {w_path.show(); setValue(value); active = true; return;}
|
||||
if (type == "e") {
|
||||
QStringList en_sl = QPIEvaluator::inBrackets(comment).split(';');
|
||||
if (en_sl.size() > 1) {
|
||||
w_enum.show();
|
||||
w_enum.addItems(en_sl);
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
} else {
|
||||
type = "s";
|
||||
}
|
||||
}
|
||||
if (type == "s") {
|
||||
w_string.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "l") {
|
||||
w_list.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "b") {
|
||||
w_bool.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "n") {
|
||||
w_integer.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "f") {
|
||||
w_float.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "c") {
|
||||
w_color.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "r") {
|
||||
w_rect.show();
|
||||
w_rect.setDecimals(0);
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "a") {
|
||||
w_rect.show();
|
||||
w_rect.setDecimals(3);
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "p") {
|
||||
w_point.show();
|
||||
w_point.setDecimals(0);
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "v") {
|
||||
w_point.show();
|
||||
w_point.setDecimals(3);
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "i") {
|
||||
w_ip.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "F") {
|
||||
w_path.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "D") {
|
||||
w_path.show();
|
||||
setValue(value);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfigValueWidget::setValue(const QString & v) {
|
||||
value = v;
|
||||
value = v;
|
||||
active = false;
|
||||
if (type == "l") {w_list.setValue(v.split("%|%")); active = true; return;}
|
||||
if (type == "b") {w_bool.setChecked(v.toInt() > 0 || v.toLower().trimmed() == "true"); active = true; return;}
|
||||
if (type == "n") {w_integer.setValue(QString2int(v)); active = true; return;}
|
||||
if (type == "f") {w_float.setValue(v.toDouble()); active = true; return;}
|
||||
if (type == "c") {w_color.setColor(QString2QColor(v)); active = true; return;}
|
||||
if (type == "r") {w_rect.setValue(QString2QRectF(v)); active = true; return;}
|
||||
if (type == "a") {w_rect.setValue(QString2QRectF(v)); active = true; return;}
|
||||
if (type == "p") {w_point.setValue(QString2QPointF(v)); active = true; return;}
|
||||
if (type == "v") {w_point.setValue(QString2QPointF(v)); active = true; return;}
|
||||
if (type == "i") {w_ip.setIP(v); active = true; return;}
|
||||
if (type == "e") {w_enum.setCurrentIndex(w_enum.findText(v)); active = true; return;}
|
||||
if (type == "F") {w_path.is_dir = false; w_path.setValue(v); active = true; return;}
|
||||
if (type == "D") {w_path.is_dir = true; w_path.setValue(v); active = true; return;}
|
||||
if (type == "l") {
|
||||
w_list.setValue(v.split("%|%"));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "b") {
|
||||
w_bool.setChecked(v.toInt() > 0 || v.toLower().trimmed() == "true");
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "n") {
|
||||
w_integer.setValue(QString2int(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "f") {
|
||||
w_float.setValue(v.toDouble());
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "c") {
|
||||
w_color.setColor(QString2QColor(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "r") {
|
||||
w_rect.setValue(QString2QRectF(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "a") {
|
||||
w_rect.setValue(QString2QRectF(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "p") {
|
||||
w_point.setValue(QString2QPointF(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "v") {
|
||||
w_point.setValue(QString2QPointF(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "i") {
|
||||
w_ip.setIP(v);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "e") {
|
||||
w_enum.setCurrentIndex(w_enum.findText(v));
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "F") {
|
||||
w_path.is_dir = false;
|
||||
w_path.setValue(v);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
if (type == "D") {
|
||||
w_path.is_dir = true;
|
||||
w_path.setValue(v);
|
||||
active = true;
|
||||
return;
|
||||
}
|
||||
w_string.setText(v);
|
||||
active = true;
|
||||
}
|
||||
@@ -80,19 +212,71 @@ void ConfigValueWidget::setValue(const QString & v) {
|
||||
|
||||
void ConfigValueWidget::valueChanged() {
|
||||
if (!active) return;
|
||||
if (type == "l") {value = w_list.value().join("%|%"); emit changed(this, value); return;}
|
||||
if (type == "b") {value = w_bool.isChecked() ? "true" : "false"; emit changed(this, value); return;}
|
||||
if (type == "n") {value = QString::number(w_integer.value()); emit changed(this, value); return;}
|
||||
if (type == "f") {value = QString::number(w_float.value()); emit changed(this, value); return;}
|
||||
if (type == "c") {value = QColor2QString(w_color.color()); emit changed(this, value); return;}
|
||||
if (type == "r") {value = QRectF2QString(w_rect.value()); emit changed(this, value); return;}
|
||||
if (type == "a") {value = QRectF2QString(w_rect.value()); emit changed(this, value); return;}
|
||||
if (type == "p") {value = QPointF2QString(w_point.value()); emit changed(this, value); return;}
|
||||
if (type == "v") {value = QPointF2QString(w_point.value()); emit changed(this, value); return;}
|
||||
if (type == "i") {value = w_ip.IP(); emit changed(this, value); return;}
|
||||
if (type == "e") {value = w_enum.currentText(); emit changed(this, value); return;}
|
||||
if (type == "F") {value = w_path.value(); emit changed(this, value); return;}
|
||||
if (type == "D") {value = w_path.value(); emit changed(this, value); return;}
|
||||
if (type == "l") {
|
||||
value = w_list.value().join("%|%");
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "b") {
|
||||
value = w_bool.isChecked() ? "true" : "false";
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "n") {
|
||||
value = QString::number(w_integer.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "f") {
|
||||
value = QString::number(w_float.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "c") {
|
||||
value = QColor2QString(w_color.color());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "r") {
|
||||
value = QRectF2QString(w_rect.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "a") {
|
||||
value = QRectF2QString(w_rect.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "p") {
|
||||
value = QPointF2QString(w_point.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "v") {
|
||||
value = QPointF2QString(w_point.value());
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "i") {
|
||||
value = w_ip.IP();
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "e") {
|
||||
value = w_enum.currentText();
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "F") {
|
||||
value = w_path.value();
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
if (type == "D") {
|
||||
value = w_path.value();
|
||||
emit changed(this, value);
|
||||
return;
|
||||
}
|
||||
value = w_string.text();
|
||||
emit changed(this, value);
|
||||
}
|
||||
|
||||
@@ -1,57 +1,75 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPICONFIGVALUEWIDGET_H
|
||||
#define QPICONFIGVALUEWIDGET_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include "qpiconfig.h"
|
||||
#include "qvariantedit.h"
|
||||
#include "qrectedit.h"
|
||||
#include "qpointedit.h"
|
||||
#include "colorbutton.h"
|
||||
#include "ecombobox.h"
|
||||
#include "qipedit.h"
|
||||
#include "limits.h"
|
||||
#include "float.h"
|
||||
#include "limits.h"
|
||||
#include "qad_widgets_export.h"
|
||||
#include "qipedit.h"
|
||||
#include "qpiconfig.h"
|
||||
#include "qpointedit.h"
|
||||
#include "qrectedit.h"
|
||||
#include "qvariantedit.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ConfigValueWidget: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT ConfigValueWidget: public QWidget {
|
||||
Q_OBJECT
|
||||
friend class QPIConfigWidget;
|
||||
friend class QPIConfigNewDialog;
|
||||
|
||||
public:
|
||||
ConfigValueWidget(QWidget * parent = 0);
|
||||
~ConfigValueWidget() {hide();}
|
||||
|
||||
~ConfigValueWidget() { hide(); }
|
||||
|
||||
void setType(const QString & t);
|
||||
void setValue(const QString & v);
|
||||
void setEntry(QPIConfig::Entry * e) {value = e->value(); full_name = e->_full_name; comment = e->comment(); setType(e->type());}
|
||||
|
||||
void setEntry(QPIConfig::Entry * e) {
|
||||
value = e->value();
|
||||
full_name = e->_full_name;
|
||||
comment = e->comment();
|
||||
setType(e->type());
|
||||
}
|
||||
|
||||
private:
|
||||
void hideAll() {w_string.hide(); w_list.hide(); w_bool.hide(); w_integer.hide(); w_float.hide(); w_color.hide(); w_rect.hide(); w_point.hide(); w_ip.hide(); w_enum.hide(); w_path.hide();}
|
||||
|
||||
void hideAll() {
|
||||
w_string.hide();
|
||||
w_list.hide();
|
||||
w_bool.hide();
|
||||
w_integer.hide();
|
||||
w_float.hide();
|
||||
w_color.hide();
|
||||
w_rect.hide();
|
||||
w_point.hide();
|
||||
w_ip.hide();
|
||||
w_enum.hide();
|
||||
w_path.hide();
|
||||
}
|
||||
|
||||
QString type, value, full_name, comment;
|
||||
bool active;
|
||||
QBoxLayout lay;
|
||||
@@ -66,13 +84,12 @@ private:
|
||||
QIPEdit w_ip;
|
||||
QComboBox w_enum;
|
||||
PathEdit w_path;
|
||||
|
||||
|
||||
private slots:
|
||||
void valueChanged();
|
||||
|
||||
|
||||
signals:
|
||||
void changed(ConfigValueWidget * , QString );
|
||||
|
||||
void changed(ConfigValueWidget *, QString);
|
||||
};
|
||||
|
||||
#endif // QPICONFIGVALUEWIDGET_H
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
#include "qpiconfigwidget.h"
|
||||
|
||||
#include "qalgorithms.h"
|
||||
#include "qpiconfigvaluewidget.h"
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on): QTreeWidget(parent), actionAddItem(this), actionAddNode(this),
|
||||
actionToItem(this), actionToNode(this), actionRemove(this),
|
||||
actionExpandAll(this), actionCollapseAll(this) {
|
||||
QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on)
|
||||
: QTreeWidget(parent)
|
||||
, actionAddItem(this)
|
||||
, actionAddNode(this)
|
||||
, actionToItem(this)
|
||||
, actionToNode(this)
|
||||
, actionRemove(this)
|
||||
, actionExpandAll(this)
|
||||
, actionCollapseAll(this) {
|
||||
active = on;
|
||||
if (active) {
|
||||
setColumnCount(4);
|
||||
@@ -32,8 +40,8 @@ QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on): QTre
|
||||
popupMenu.addAction(&actionExpandAll);
|
||||
popupMenu.addAction(&actionCollapseAll);
|
||||
viewport()->installEventFilter(this);
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem * , int)), this, SLOT(itemClicked(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem * , int)), this, SLOT(itemChanged(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *, int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(itemChanged(QTreeWidgetItem *, int)));
|
||||
connect(&actionAddItem, SIGNAL(triggered()), this, SLOT(on_actionAddItem_triggered()));
|
||||
connect(&actionAddNode, SIGNAL(triggered()), this, SLOT(on_actionAddNode_triggered()));
|
||||
connect(&actionRemove, SIGNAL(triggered()), this, SLOT(on_actionRemove_triggered()));
|
||||
@@ -58,18 +66,18 @@ void QPIConfigWidget::changeEvent(QEvent * e) {
|
||||
|
||||
bool QPIConfigWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (viewport() == qobject_cast<QWidget * >(o)) {
|
||||
pi = itemAt(((QMouseEvent * )e)->pos());
|
||||
if (((QMouseEvent * )e)->buttons() == Qt::RightButton) {
|
||||
if (viewport() == qobject_cast<QWidget *>(o)) {
|
||||
pi = itemAt(((QMouseEvent *)e)->pos());
|
||||
if (((QMouseEvent *)e)->buttons() == Qt::RightButton) {
|
||||
qApp->processEvents();
|
||||
itemClicked(pi, 1);
|
||||
popupMenu.popup(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent * )e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent * )e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent *)e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent *)e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +111,7 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (item != c_pi) {
|
||||
c_pi = item;
|
||||
if (item) {
|
||||
c_name = item->text(0);
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
}
|
||||
return;
|
||||
@@ -114,7 +122,7 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (c_name == item->text(0) && c_comment == item->text(3)) {
|
||||
return;
|
||||
}
|
||||
//qDebug() << "change" << item->text(0);
|
||||
// qDebug() << "change" << item->text(0);
|
||||
QPIConfig::Entry * e = itemEntry(item);
|
||||
if (e == nullptr) {
|
||||
return;
|
||||
@@ -123,12 +131,12 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
buildFullNames(item);
|
||||
e->setName(item->text(column));
|
||||
conf->buildFullNames(e->parent());
|
||||
//qDebug() << itemCWidget(item)->full_name;
|
||||
// qDebug() << itemCWidget(item)->full_name;
|
||||
}
|
||||
if (column == 3) {
|
||||
e->setComment(item->text(column));
|
||||
}
|
||||
c_name = item->text(0);
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
emit changed();
|
||||
}
|
||||
@@ -164,10 +172,10 @@ void QPIConfigWidget::on_actionAddItem_triggered() {
|
||||
}
|
||||
QPIConfig::Entry * e;
|
||||
if (pi->childCount() == 0) {
|
||||
//qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
|
||||
// qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
|
||||
conf->removeEntry(itemCWidget(pi)->full_name, false);
|
||||
}
|
||||
//qDebug() << "add " << fp + new_dialog.name();
|
||||
// qDebug() << "add " << fp + new_dialog.name();
|
||||
e = &(conf->addEntry(fp + new_dialog.name(), new_dialog.value().isEmpty() ? "0" : new_dialog.value(), new_dialog.type(), false));
|
||||
expandItem(pi);
|
||||
pi = addEntry(pi, e);
|
||||
@@ -212,18 +220,18 @@ void QPIConfigWidget::on_actionRemove_triggered() {
|
||||
if (conf == nullptr || !active) {
|
||||
return;
|
||||
}
|
||||
QList<QTreeWidgetItem * > si = selectedItems();
|
||||
QList<QTreeWidgetItem *> si = selectedItems();
|
||||
conf->buildFullNames(&(conf->root));
|
||||
QPIConfig::Entry * e;
|
||||
for (QTreeWidgetItem * i : si) {
|
||||
for (QTreeWidgetItem * i: si) {
|
||||
e = itemEntry(i);
|
||||
if (e == nullptr) continue;
|
||||
//qDebug() << "remove " + e->_full_name;
|
||||
// qDebug() << "remove " + e->_full_name;
|
||||
conf->removeEntry(e->_full_name, false);
|
||||
deleteEntry(i);
|
||||
}
|
||||
emit changed();
|
||||
//show();
|
||||
// show();
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +262,7 @@ void QPIConfigWidget::buildTree() {
|
||||
|
||||
void QPIConfigWidget::setReadOnlyValue(bool yes) {
|
||||
read_only_value = yes;
|
||||
for (ConfigValueWidget * i : w_values) {
|
||||
for (ConfigValueWidget * i: w_values) {
|
||||
i->setEnabled(!yes);
|
||||
}
|
||||
}
|
||||
@@ -262,7 +270,7 @@ void QPIConfigWidget::setReadOnlyValue(bool yes) {
|
||||
|
||||
void QPIConfigWidget::setReadOnlyType(bool yes) {
|
||||
read_only_type = yes;
|
||||
for (QComboBox * i : w_types) {
|
||||
for (QComboBox * i: w_types) {
|
||||
i->setEnabled(!yes);
|
||||
i->setFrame(!yes);
|
||||
}
|
||||
@@ -270,17 +278,17 @@ void QPIConfigWidget::setReadOnlyType(bool yes) {
|
||||
|
||||
|
||||
void QPIConfigWidget::buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e) {
|
||||
for (QPIConfig::Entry * j : e->children()) {
|
||||
for (QPIConfig::Entry * j: e->children()) {
|
||||
buildEntry(addEntry(i, j, !j->isLeaf()), j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::buildFullNames(QTreeWidgetItem * i) {
|
||||
ConfigValueWidget * cw, * pw;
|
||||
ConfigValueWidget *cw, *pw;
|
||||
cw = itemCWidget(i);
|
||||
if (i->parent()) {
|
||||
pw = itemCWidget(i->parent());
|
||||
pw = itemCWidget(i->parent());
|
||||
cw->full_name = pw->full_name + conf->delim + i->text(0);
|
||||
} else {
|
||||
cw->full_name = i->text(0);
|
||||
@@ -315,9 +323,9 @@ QTreeWidgetItem * QPIConfigWidget::addEntry(QTreeWidgetItem * i, QPIConfig::Entr
|
||||
w_types.back()->setProperty("qpic_widget", QVariant(reinterpret_cast<qlonglong>(w_values.back())));
|
||||
w_types.back()->setEnabled(!read_only_type);
|
||||
w_types.back()->setFrame(!read_only_type);
|
||||
connect(w_types.back(), SIGNAL(currentIndexChanged(int, UComboBox * )), this, SLOT(typeChange(int,UComboBox * )));
|
||||
connect(w_types.back(), SIGNAL(currentIndexChanged(int, UComboBox *)), this, SLOT(typeChange(int, UComboBox *)));
|
||||
}
|
||||
connect(w_values.back(), SIGNAL(changed(ConfigValueWidget * , QString)), this, SLOT(valueChange(ConfigValueWidget * , QString)));
|
||||
connect(w_values.back(), SIGNAL(changed(ConfigValueWidget *, QString)), this, SLOT(valueChange(ConfigValueWidget *, QString)));
|
||||
i->addChild(ti);
|
||||
setItemWidget(ti, 1, w_values.back());
|
||||
if (!node) {
|
||||
@@ -338,8 +346,8 @@ void QPIConfigWidget::deleteEntry(QTreeWidgetItem * i) {
|
||||
for (int j = 0; j < cc; ++j) {
|
||||
deleteEntry(i->child(0));
|
||||
}
|
||||
vw = qobject_cast<ConfigValueWidget * >(itemWidget(i, 1));
|
||||
cb = qobject_cast<UComboBox * >(itemWidget(i, 2));
|
||||
vw = qobject_cast<ConfigValueWidget *>(itemWidget(i, 1));
|
||||
cb = qobject_cast<UComboBox *>(itemWidget(i, 2));
|
||||
if (vw) {
|
||||
w_values.remove(w_values.indexOf(vw));
|
||||
delete vw;
|
||||
@@ -373,8 +381,8 @@ bool QPIConfigWidget::filterItem(const QString & f, QTreeWidgetItem * i) {
|
||||
return true;
|
||||
}
|
||||
bool ret = (!isColumnHidden(0) && i->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(1) && itemCWidget(i)->value.indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(3) && i->text(3).indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
(!isColumnHidden(1) && itemCWidget(i)->value.indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(3) && i->text(3).indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
if (itemTWidget(i)) {
|
||||
ret = ret || (!isColumnHidden(2) && itemTWidget(i)->currentText().indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
}
|
||||
@@ -434,12 +442,12 @@ void QPIConfigWidget::readFromString(QString str) {
|
||||
}
|
||||
|
||||
|
||||
UComboBox::UComboBox(QWidget *parent) : QComboBox(parent) {
|
||||
UComboBox::UComboBox(QWidget * parent): QComboBox(parent) {
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChange(int)));
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::filter(const QString &f) {
|
||||
void QPIConfigWidget::filter(const QString & f) {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
@@ -499,23 +507,23 @@ void QPIConfigWidget::setReadOnlyName(bool yes) {
|
||||
}
|
||||
|
||||
|
||||
ConfigValueWidget *QPIConfigWidget::itemCWidget(QTreeWidgetItem *i) {
|
||||
ConfigValueWidget * QPIConfigWidget::itemCWidget(QTreeWidgetItem * i) {
|
||||
return qobject_cast<ConfigValueWidget *>(itemWidget(i, 1));
|
||||
}
|
||||
|
||||
|
||||
UComboBox *QPIConfigWidget::itemTWidget(QTreeWidgetItem *i) {
|
||||
UComboBox * QPIConfigWidget::itemTWidget(QTreeWidgetItem * i) {
|
||||
return qobject_cast<UComboBox *>(itemWidget(i, 2));
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::addTrEntry(const QString &s, const QString &f) {
|
||||
void QPIConfigWidget::addTrEntry(const QString & s, const QString & f) {
|
||||
types.insert(s, f);
|
||||
s_types << f;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::setQPIConfig(QPIConfig *c) {
|
||||
void QPIConfigWidget::setQPIConfig(QPIConfig * c) {
|
||||
conf = c;
|
||||
buildTree();
|
||||
}
|
||||
@@ -524,4 +532,3 @@ void QPIConfigWidget::setQPIConfig(QPIConfig *c) {
|
||||
void UComboBox::indexChange(int i) {
|
||||
emit currentIndexChanged(i, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPICONFIGWIDGET_H
|
||||
@@ -23,31 +23,31 @@
|
||||
#include "qad_widgets_export.h"
|
||||
#include "qpiconfig.h"
|
||||
#include "qpiconfignewdialog.h"
|
||||
#include <QComboBox>
|
||||
#include <QTreeWidget>
|
||||
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QMenu>
|
||||
#include <QTreeWidget>
|
||||
|
||||
|
||||
class ConfigValueWidget;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT UComboBox: public QComboBox
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT UComboBox: public QComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UComboBox(QWidget *parent = nullptr);
|
||||
UComboBox(QWidget * parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void indexChange(int i);
|
||||
signals:
|
||||
|
||||
void currentIndexChanged(int, UComboBox * );
|
||||
void currentIndexChanged(int, UComboBox *);
|
||||
};
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QPIConfigWidget: public QTreeWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT QPIConfigWidget: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool readOnlyName READ readOnlyName WRITE setReadOnlyName)
|
||||
Q_PROPERTY(bool readOnlyValue READ readOnlyValue WRITE setReadOnlyValue)
|
||||
@@ -57,28 +57,29 @@ class QAD_WIDGETS_EXPORT QPIConfigWidget: public QTreeWidget
|
||||
Q_PROPERTY(bool columnValueVisible READ columnValueVisible WRITE setColumnValueVisible)
|
||||
Q_PROPERTY(bool columnTypeVisible READ columnTypeVisible WRITE setColumnTypeVisible)
|
||||
Q_PROPERTY(bool columnCommentVisible READ columnCommentVisible WRITE setColumnCommentVisible)
|
||||
|
||||
public:
|
||||
QPIConfigWidget(QWidget * parent = nullptr, QPIConfig * c = nullptr, bool on = true);
|
||||
~QPIConfigWidget() override {clear();}
|
||||
~QPIConfigWidget() override { clear(); }
|
||||
|
||||
void setQPIConfig(QPIConfig *c);
|
||||
bool readOnlyName() {return read_only_name;}
|
||||
bool readOnlyValue() {return read_only_value;}
|
||||
bool readOnlyType() {return read_only_type;}
|
||||
bool readOnlyComment() {return read_only_comment;}
|
||||
bool columnNameVisible() {return !c_hidden[0];}
|
||||
bool columnValueVisible() {return !c_hidden[1];}
|
||||
bool columnTypeVisible() {return !c_hidden[2];}
|
||||
bool columnCommentVisible() {return !c_hidden[3];}
|
||||
void setQPIConfig(QPIConfig * c);
|
||||
bool readOnlyName() { return read_only_name; }
|
||||
bool readOnlyValue() { return read_only_value; }
|
||||
bool readOnlyType() { return read_only_type; }
|
||||
bool readOnlyComment() { return read_only_comment; }
|
||||
bool columnNameVisible() { return !c_hidden[0]; }
|
||||
bool columnValueVisible() { return !c_hidden[1]; }
|
||||
bool columnTypeVisible() { return !c_hidden[2]; }
|
||||
bool columnCommentVisible() { return !c_hidden[3]; }
|
||||
QString writeToString();
|
||||
void readFromString(QString str);
|
||||
|
||||
|
||||
public slots:
|
||||
void parse();
|
||||
void write();
|
||||
void clear();
|
||||
void buildTree();
|
||||
void filter(const QString &f);
|
||||
void filter(const QString & f);
|
||||
void setReadOnlyName(bool yes);
|
||||
void setReadOnlyValue(bool yes);
|
||||
void setReadOnlyType(bool yes);
|
||||
@@ -96,7 +97,7 @@ private slots:
|
||||
void on_actionAddItem_triggered();
|
||||
void on_actionAddNode_triggered();
|
||||
void on_actionRemove_triggered();
|
||||
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
@@ -106,25 +107,25 @@ private:
|
||||
void buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e);
|
||||
void buildFullNames(QTreeWidgetItem * i);
|
||||
QPIConfig::Entry * itemEntry(QTreeWidgetItem * i);
|
||||
ConfigValueWidget *itemCWidget(QTreeWidgetItem *i);
|
||||
UComboBox *itemTWidget(QTreeWidgetItem *i);
|
||||
ConfigValueWidget * itemCWidget(QTreeWidgetItem * i);
|
||||
UComboBox * itemTWidget(QTreeWidgetItem * i);
|
||||
QTreeWidgetItem * addEntry(QTreeWidgetItem * i, QPIConfig::Entry * e, bool node = false);
|
||||
void deleteEntry(QTreeWidgetItem * i);
|
||||
bool filter(const QString & f, QTreeWidgetItem * i);
|
||||
bool filterItem(const QString & f, QTreeWidgetItem * i);
|
||||
void translate();
|
||||
void addTrEntry(const QString &s, const QString &f);
|
||||
void addTrEntry(const QString & s, const QString & f);
|
||||
|
||||
QPIConfig * conf;
|
||||
QPIConfigNewDialog new_dialog;
|
||||
QAction actionAddItem, actionAddNode, actionToItem, actionToNode, actionRemove, actionExpandAll, actionCollapseAll;
|
||||
QMenu popupMenu;
|
||||
QString c_name, c_comment;
|
||||
QTreeWidgetItem * pi, * ti, * c_pi;
|
||||
QTreeWidgetItem *pi, *ti, *c_pi;
|
||||
QHash<QString, QString> types;
|
||||
QStringList s_types;
|
||||
QVector<ConfigValueWidget * > w_values;
|
||||
QVector<UComboBox * > w_types;
|
||||
QVector<ConfigValueWidget *> w_values;
|
||||
QVector<UComboBox *> w_types;
|
||||
QVector<bool> c_hidden;
|
||||
bool active, read_only_name, read_only_value, read_only_type, read_only_comment;
|
||||
};
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
QPIConsole::QPIConsole(QWidget * parent): QTabWidget(parent) {
|
||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
|
||||
cur_tab = timer = -1;
|
||||
def_align = Qt::AlignCenter;
|
||||
def_align = Qt::AlignCenter;
|
||||
}
|
||||
|
||||
|
||||
void QPIConsole::timerEvent(QTimerEvent * ) {
|
||||
void QPIConsole::timerEvent(QTimerEvent *) {
|
||||
for (int i = 0; i < columns().size(); ++i) {
|
||||
Column & ccol(tabs[cur_tab].columns[i]);
|
||||
QVector<Variable> & cvars(ccol.variables);
|
||||
@@ -38,21 +38,23 @@ void QPIConsole::timerEvent(QTimerEvent * ) {
|
||||
if (tv.type <= 0 && tv.ptr == 0) continue;
|
||||
if (tv.ptr != 0) {
|
||||
switch (tv.type) {
|
||||
case 0: tv.widget->setText((tv.ptr != 0 ? *(const QString*)tv.ptr : QString())); break;
|
||||
case 1: tv.widget->setText((tv.ptr != 0 ? *(const bool*)tv.ptr : false) ? "true" : "false"); break;
|
||||
case 2: tv.widget->setText(numIntString<int>(tv.ptr != 0 ? *(const int*)tv.ptr : 0, tv.format)); break;
|
||||
case 3: tv.widget->setText(numIntString<long>(tv.ptr != 0 ? *(const long*)tv.ptr : 0l, tv.format)); break;
|
||||
case 4: tv.widget->setText(QString(tv.ptr != 0 ? *(const char*)tv.ptr : char(0))); break;
|
||||
case 5: tv.widget->setText(numFloatString<float>(tv.ptr != 0 ? *(const float*)tv.ptr : 0.f, tv.format)); break;
|
||||
case 6: tv.widget->setText(numFloatString<double>(tv.ptr != 0 ? *(const double*)tv.ptr : 0., tv.format)); break;
|
||||
case 7: tv.widget->setText(numFloatString<short>(tv.ptr != 0 ? *(const short*)tv.ptr : short(0), tv.format)); break;
|
||||
case 8: tv.widget->setText(numIntString<uint>(tv.ptr != 0 ? *(const uint*)tv.ptr : 0u, tv.format)); break;
|
||||
case 9: tv.widget->setText(numIntString<ulong>(tv.ptr != 0 ? *(const ulong*)tv.ptr : 0ul, tv.format)); break;
|
||||
case 10: tv.widget->setText(numIntString<ushort>(tv.ptr != 0 ? *(const ushort*)tv.ptr : ushort(0), tv.format)); break;
|
||||
case 11: tv.widget->setText(numIntString<uchar>(tv.ptr != 0 ? *(const uchar*)tv.ptr : uchar(0), tv.format)); break;
|
||||
case 12: tv.widget->setText(numIntString<llong>(tv.ptr != 0 ? *(const llong*)tv.ptr : 0l, tv.format)); break;
|
||||
case 13: tv.widget->setText(numIntString<ullong>(tv.ptr != 0 ? *(const ullong*)tv.ptr: 0ull, tv.format)); break;
|
||||
case 14: tv.widget->setText(numIntString<int>(bitsValue(tv.ptr, tv.bitFrom, tv.bitCount), tv.format, tv.bitCount/8)); break;
|
||||
case 0: tv.widget->setText((tv.ptr != 0 ? *(const QString *)tv.ptr : QString())); break;
|
||||
case 1: tv.widget->setText((tv.ptr != 0 ? *(const bool *)tv.ptr : false) ? "true" : "false"); break;
|
||||
case 2: tv.widget->setText(numIntString<int>(tv.ptr != 0 ? *(const int *)tv.ptr : 0, tv.format)); break;
|
||||
case 3: tv.widget->setText(numIntString<long>(tv.ptr != 0 ? *(const long *)tv.ptr : 0l, tv.format)); break;
|
||||
case 4: tv.widget->setText(QString(tv.ptr != 0 ? *(const char *)tv.ptr : char(0))); break;
|
||||
case 5: tv.widget->setText(numFloatString<float>(tv.ptr != 0 ? *(const float *)tv.ptr : 0.f, tv.format)); break;
|
||||
case 6: tv.widget->setText(numFloatString<double>(tv.ptr != 0 ? *(const double *)tv.ptr : 0., tv.format)); break;
|
||||
case 7: tv.widget->setText(numFloatString<short>(tv.ptr != 0 ? *(const short *)tv.ptr : short(0), tv.format)); break;
|
||||
case 8: tv.widget->setText(numIntString<uint>(tv.ptr != 0 ? *(const uint *)tv.ptr : 0u, tv.format)); break;
|
||||
case 9: tv.widget->setText(numIntString<ulong>(tv.ptr != 0 ? *(const ulong *)tv.ptr : 0ul, tv.format)); break;
|
||||
case 10: tv.widget->setText(numIntString<ushort>(tv.ptr != 0 ? *(const ushort *)tv.ptr : ushort(0), tv.format)); break;
|
||||
case 11: tv.widget->setText(numIntString<uchar>(tv.ptr != 0 ? *(const uchar *)tv.ptr : uchar(0), tv.format)); break;
|
||||
case 12: tv.widget->setText(numIntString<llong>(tv.ptr != 0 ? *(const llong *)tv.ptr : 0l, tv.format)); break;
|
||||
case 13: tv.widget->setText(numIntString<ullong>(tv.ptr != 0 ? *(const ullong *)tv.ptr : 0ull, tv.format)); break;
|
||||
case 14:
|
||||
tv.widget->setText(numIntString<int>(bitsValue(tv.ptr, tv.bitFrom, tv.bitCount), tv.format, tv.bitCount / 8));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -61,65 +63,149 @@ void QPIConsole::timerEvent(QTimerEvent * ) {
|
||||
}
|
||||
|
||||
|
||||
#define ADD_VAR_BODY tv.name = name; if (!tv.name.isEmpty()) tv.name += ":"; tv.bitFrom = tv.bitCount = 0; tv.format = format; checkColumn(col);
|
||||
#define ADD_VAR_SBODY tv.name = name; tv.bitFrom = tv.bitCount = 0; tv.format = format; checkColumn(col);
|
||||
#define ADD_VAR_BODY \
|
||||
tv.name = name; \
|
||||
if (!tv.name.isEmpty()) tv.name += ":"; \
|
||||
tv.bitFrom = tv.bitCount = 0; \
|
||||
tv.format = format; \
|
||||
checkColumn(col);
|
||||
#define ADD_VAR_SBODY \
|
||||
tv.name = name; \
|
||||
tv.bitFrom = tv.bitCount = 0; \
|
||||
tv.format = format; \
|
||||
checkColumn(col);
|
||||
|
||||
#define ADD_VAR_QT QLabel * lbl = new QLabel(name); QLabel * w = new QLabel(); \
|
||||
lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \
|
||||
column(col).variables.back().label = lbl; column(col).variables.back().widget = w; \
|
||||
lbl->setAlignment(column(col).alignment); \
|
||||
applyFormat(lbl, format); applyFormat(w, format); \
|
||||
column(col).layout->addRow(lbl, w);
|
||||
#define ADD_VAR_QT \
|
||||
QLabel * lbl = new QLabel(name); \
|
||||
QLabel * w = new QLabel(); \
|
||||
lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \
|
||||
column(col).variables.back().label = lbl; \
|
||||
column(col).variables.back().widget = w; \
|
||||
lbl->setAlignment(column(col).alignment); \
|
||||
applyFormat(lbl, format); \
|
||||
applyFormat(w, format); \
|
||||
column(col).layout->addRow(lbl, w);
|
||||
|
||||
void QPIConsole::addString(const QString & name, int col, Formats format) {
|
||||
ADD_VAR_SBODY tv.type = -1; tv.ptr = 0; column(col).push_back(tv);
|
||||
ADD_VAR_SBODY tv.type = -1;
|
||||
tv.ptr = 0;
|
||||
column(col).push_back(tv);
|
||||
QLabel * lbl = new QLabel(name);
|
||||
lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
column(col).variables.back().label = lbl; column(col).variables.back().widget = 0;
|
||||
column(col).variables.back().label = lbl;
|
||||
column(col).variables.back().widget = 0;
|
||||
lbl->setAlignment(column(col).alignment);
|
||||
applyFormat(lbl, format);
|
||||
column(col).layout->addRow(lbl);
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const QString* ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 0; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
void QPIConsole::addVariable(const QString & name, const QString * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 0;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const bool * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 1; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 1;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const int * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 2; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 2;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const long * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 3; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 3;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const char * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 4; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 4;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const float * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 5; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 5;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const double * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 6; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 6;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const short * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 7; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 7;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const uint * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 8; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 8;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const ulong * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 9; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 9;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const ushort * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 10; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 10;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const uchar * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 11; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 11;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const llong * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 12; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 12;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addVariable(const QString & name, const ullong * ptr, int col, Formats format) {
|
||||
ADD_VAR_BODY tv.type = 13; tv.ptr = ptr; column(col).push_back(tv); ADD_VAR_QT}
|
||||
ADD_VAR_BODY tv.type = 13;
|
||||
tv.ptr = ptr;
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addBitVariable(const QString & name, const void * ptr, int fromBit, int bitCount, int col, Formats format) {
|
||||
tv.name = name; tv.bitFrom = fromBit; tv.bitCount = bitCount; tv.type = 14; tv.ptr = ptr; tv.format = format;
|
||||
checkColumn(col); column(col).push_back(tv); ADD_VAR_QT}
|
||||
tv.name = name;
|
||||
tv.bitFrom = fromBit;
|
||||
tv.bitCount = bitCount;
|
||||
tv.type = 14;
|
||||
tv.ptr = ptr;
|
||||
tv.format = format;
|
||||
checkColumn(col);
|
||||
column(col).push_back(tv);
|
||||
ADD_VAR_QT
|
||||
}
|
||||
void QPIConsole::addEmptyLine(int col, uint count) {
|
||||
tv.name = ""; tv.type = 0; tv.ptr = 0; tv.format = Normal;
|
||||
tv.name = "";
|
||||
tv.type = 0;
|
||||
tv.ptr = 0;
|
||||
tv.format = Normal;
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
checkColumn(col);
|
||||
column(col).push_back(tv);
|
||||
QLabel * lbl = new QLabel();
|
||||
lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
column(col).variables.back().label = lbl; column(col).variables.back().widget = 0;
|
||||
column(col).variables.back().label = lbl;
|
||||
column(col).variables.back().widget = 0;
|
||||
lbl->setAlignment(column(col).alignment);
|
||||
applyFormat(lbl, tv.format);
|
||||
column(col).layout->addRow(lbl);
|
||||
@@ -128,10 +214,10 @@ void QPIConsole::addEmptyLine(int col, uint count) {
|
||||
|
||||
|
||||
int QPIConsole::addTab(const QString & name, char bind_key) {
|
||||
QWidget * w = new QWidget();
|
||||
QVBoxLayout * lay = new QVBoxLayout();
|
||||
QWidget * w = new QWidget();
|
||||
QVBoxLayout * lay = new QVBoxLayout();
|
||||
QHBoxLayout * clay = new QHBoxLayout();
|
||||
QLabel * lbl = new QLabel();
|
||||
QLabel * lbl = new QLabel();
|
||||
lay->setContentsMargins(2, 2, 2, 2);
|
||||
clay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->addLayout(clay);
|
||||
@@ -142,7 +228,7 @@ int QPIConsole::addTab(const QString & name, char bind_key) {
|
||||
tabs.push_back(Tab(name, bind_key));
|
||||
tabs.back().layout = clay;
|
||||
tabs.back().widget = lbl;
|
||||
cur_tab = tabs.size() - 1;
|
||||
cur_tab = tabs.size() - 1;
|
||||
setCurrentIndex(cur_tab);
|
||||
return tabs.size();
|
||||
}
|
||||
@@ -162,14 +248,14 @@ void QPIConsole::checkColumn(int col) {
|
||||
|
||||
int QPIConsole::bitsValue(const void * src, int offset, int count) const {
|
||||
int ret = 0, stbyte = offset / 8, cbit = offset - stbyte * 8;
|
||||
char cbyte = reinterpret_cast<const char * >(src)[stbyte];
|
||||
char cbyte = reinterpret_cast<const char *>(src)[stbyte];
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret |= ((cbyte >> cbit & 1) << i);
|
||||
cbit++;
|
||||
if (cbit == 8) {
|
||||
cbit = 0;
|
||||
stbyte++;
|
||||
cbyte = reinterpret_cast<const char * >(src)[stbyte];
|
||||
cbyte = reinterpret_cast<const char *>(src)[stbyte];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -181,7 +267,7 @@ const QString & QPIConsole::toBin(const void * d, int s) {
|
||||
uchar cc, b;
|
||||
for (int i = 0; i < s; ++i) {
|
||||
cc = ((const uchar *)d)[i];
|
||||
b = 1;
|
||||
b = 1;
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
binstr.prepend(cc & b ? "1" : "0");
|
||||
b <<= 1;
|
||||
@@ -195,7 +281,7 @@ const QString & QPIConsole::toBin(const void * d, int s) {
|
||||
void QPIConsole::applyFormat(QLabel * l, QPIConsole::Formats f) {
|
||||
QColor fcol = Qt::black, bcol = QColor(0xFFFFFF);
|
||||
QFont fnt = font();
|
||||
|
||||
|
||||
if (f.testFlag(QPIConsole::Bold)) fnt.setBold(true);
|
||||
if (f.testFlag(QPIConsole::Italic)) fnt.setItalic(true);
|
||||
if (f.testFlag(QPIConsole::Underline)) fnt.setUnderline(true);
|
||||
@@ -220,14 +306,14 @@ void QPIConsole::applyFormat(QLabel * l, QPIConsole::Formats f) {
|
||||
if (f.testFlag(QPIConsole::BackCyan)) bcol = Qt::cyan;
|
||||
if (f.testFlag(QPIConsole::BackWhite)) bcol = Qt::white;
|
||||
if (f.testFlag(QPIConsole::BackLighter)) bcol = bcol.lighter(150);
|
||||
//if (f.testFlag(QPIConsole::BackDarker)) bcol = bcol.darker(150);
|
||||
|
||||
// if (f.testFlag(QPIConsole::BackDarker)) bcol = bcol.darker(150);
|
||||
|
||||
if (f.testFlag(QPIConsole::Inverse)) {
|
||||
QColor tc = fcol;
|
||||
fcol = bcol;
|
||||
bcol = tc;
|
||||
fcol = bcol;
|
||||
bcol = tc;
|
||||
}
|
||||
|
||||
|
||||
l->setFont(fnt);
|
||||
QPalette pal = palette();
|
||||
pal.setColor(QPalette::WindowText, fcol);
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPICONSOLE_H
|
||||
#define QPICONSOLE_H
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QSpacerItem>
|
||||
#include <QDebug>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QSpacerItem>
|
||||
#include <QTabWidget>
|
||||
|
||||
|
||||
typedef long long llong;
|
||||
typedef unsigned char uchar;
|
||||
@@ -40,44 +41,46 @@ typedef long double ldouble;
|
||||
|
||||
class QAD_WIDGETS_EXPORT QPIConsole: public QTabWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QPIConsole(QWidget * parent = 0);
|
||||
|
||||
enum Format {Normal = 0x01,
|
||||
Bold = 0x02,
|
||||
Italic = 0x08,
|
||||
Underline = 0x10,
|
||||
Inverse = 0x40,
|
||||
Black = 0x100,
|
||||
Red = 0x200,
|
||||
Green = 0x400,
|
||||
Yellow = 0x800,
|
||||
Blue = 0x1000,
|
||||
Magenta = 0x2000,
|
||||
Cyan = 0x4000,
|
||||
White = 0x8000,
|
||||
BackBlack = 0x10000,
|
||||
BackRed = 0x20000,
|
||||
BackGreen = 0x40000,
|
||||
BackYellow = 0x80000,
|
||||
BackBlue = 0x100000,
|
||||
BackMagenta = 0x200000,
|
||||
BackCyan = 0x400000,
|
||||
BackWhite = 0x800000,
|
||||
Dec = 0x1000000,
|
||||
Hex = 0x2000000,
|
||||
Oct = 0x4000000,
|
||||
Bin = 0x8000000,
|
||||
Scientific = 0x10000000,
|
||||
Lighter = 0x20000000,
|
||||
Darker = 0x40000000,
|
||||
BackLighter = 0x80000000
|
||||
};
|
||||
|
||||
|
||||
enum Format {
|
||||
Normal = 0x01,
|
||||
Bold = 0x02,
|
||||
Italic = 0x08,
|
||||
Underline = 0x10,
|
||||
Inverse = 0x40,
|
||||
Black = 0x100,
|
||||
Red = 0x200,
|
||||
Green = 0x400,
|
||||
Yellow = 0x800,
|
||||
Blue = 0x1000,
|
||||
Magenta = 0x2000,
|
||||
Cyan = 0x4000,
|
||||
White = 0x8000,
|
||||
BackBlack = 0x10000,
|
||||
BackRed = 0x20000,
|
||||
BackGreen = 0x40000,
|
||||
BackYellow = 0x80000,
|
||||
BackBlue = 0x100000,
|
||||
BackMagenta = 0x200000,
|
||||
BackCyan = 0x400000,
|
||||
BackWhite = 0x800000,
|
||||
Dec = 0x1000000,
|
||||
Hex = 0x2000000,
|
||||
Oct = 0x4000000,
|
||||
Bin = 0x8000000,
|
||||
Scientific = 0x10000000,
|
||||
Lighter = 0x20000000,
|
||||
Darker = 0x40000000,
|
||||
BackLighter = 0x80000000
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(Formats, Format)
|
||||
Q_FLAGS(Formats)
|
||||
Q_ENUMS(Format)
|
||||
|
||||
|
||||
Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
|
||||
|
||||
void addString(const QString & name, int column = 1, Formats format = QPIConsole::Normal);
|
||||
@@ -95,41 +98,58 @@ public:
|
||||
void addVariable(const QString & name, const ullong * ptr, int column = 1, Formats format = QPIConsole::Normal);
|
||||
void addVariable(const QString & name, const float * ptr, int column = 1, Formats format = QPIConsole::Normal);
|
||||
void addVariable(const QString & name, const double * ptr, int column = 1, Formats format = QPIConsole::Normal);
|
||||
void addBitVariable(const QString & name, const void * ptr, int fromBit, int bitCount, int column = 1, Formats format = QPIConsole::Normal);
|
||||
void
|
||||
addBitVariable(const QString & name, const void * ptr, int fromBit, int bitCount, int column = 1, Formats format = QPIConsole::Normal);
|
||||
void addEmptyLine(int column = 1, uint count = 1);
|
||||
|
||||
uint tabsCount() const {return tabs.size();}
|
||||
QString currentTab() const {return tabs[cur_tab].name;}
|
||||
uint tabsCount() const { return tabs.size(); }
|
||||
QString currentTab() const { return tabs[cur_tab].name; }
|
||||
int addTab(const QString & name, char bind_key = 0);
|
||||
bool removeTab(uint index);
|
||||
bool removeTab(const QString & name) {return removeTab(tabIndex(name));}
|
||||
bool removeTab(const QString & name) { return removeTab(tabIndex(name)); }
|
||||
bool renameTab(uint index, const QString & new_name);
|
||||
bool renameTab(const QString & name, const QString & new_name) {return renameTab(tabIndex(name), new_name);}
|
||||
bool renameTab(const QString & name, const QString & new_name) { return renameTab(tabIndex(name), new_name); }
|
||||
void setTabEnabled(int index, bool on);
|
||||
bool setTab(uint index);
|
||||
bool setTab(const QString & name) {return setTab(tabIndex(name));}
|
||||
//void clearTabs(bool clearScreen = true) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} tabs.clear();}
|
||||
bool setTab(const QString & name) { return setTab(tabIndex(name)); }
|
||||
// void clearTabs(bool clearScreen = true) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} tabs.clear();}
|
||||
|
||||
void addCustomStatus(const QString & str, Formats format = QPIConsole::Normal) {tabs[cur_tab].widget->setText(str); applyFormat(tabs[cur_tab].widget, format);}
|
||||
void clearCustomStatus() {tabs[cur_tab].widget->clear();}
|
||||
Qt::Alignment defaultAlignment() const {return def_align;}
|
||||
void setDefaultAlignment(Qt::Alignment align) {def_align = align;}
|
||||
void setColumnAlignment(int col, Qt::Alignment align) {if (col < 0 || col >= columns().size()) return; column(col).alignment = align;}
|
||||
void setColumnAlignmentToAll(Qt::Alignment align) {for (int i = 0; i < tabs.size(); ++i) for (int j = 0; j < tabs[i].columns.size(); ++j) tabs[i].columns[j].alignment = align;/* fillLabels();*/}
|
||||
void addCustomStatus(const QString & str, Formats format = QPIConsole::Normal) {
|
||||
tabs[cur_tab].widget->setText(str);
|
||||
applyFormat(tabs[cur_tab].widget, format);
|
||||
}
|
||||
void clearCustomStatus() { tabs[cur_tab].widget->clear(); }
|
||||
Qt::Alignment defaultAlignment() const { return def_align; }
|
||||
void setDefaultAlignment(Qt::Alignment align) { def_align = align; }
|
||||
void setColumnAlignment(int col, Qt::Alignment align) {
|
||||
if (col < 0 || col >= columns().size()) return;
|
||||
column(col).alignment = align;
|
||||
}
|
||||
void setColumnAlignmentToAll(Qt::Alignment align) {
|
||||
for (int i = 0; i < tabs.size(); ++i)
|
||||
for (int j = 0; j < tabs[i].columns.size(); ++j)
|
||||
tabs[i].columns[j].alignment = align; /* fillLabels();*/
|
||||
}
|
||||
|
||||
void clearVariables() {clearVariables(true);}
|
||||
void clearVariables(bool clearScreen) {/*if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();}*/ columns().clear();}
|
||||
void clearVariables() { clearVariables(true); }
|
||||
void clearVariables(bool clearScreen) { /*if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();}*/
|
||||
columns().clear();
|
||||
}
|
||||
|
||||
private:
|
||||
void timerEvent(QTimerEvent * );
|
||||
QSize sizeHint() const {return QSize(100, 100);}
|
||||
void timerEvent(QTimerEvent *);
|
||||
QSize sizeHint() const { return QSize(100, 100); }
|
||||
|
||||
void checkColumn(int col);
|
||||
void applyFormat(QLabel * l, Formats f);
|
||||
int bitsValue(const void * src, int offset, int count) const;
|
||||
int tabIndex(const QString & n) const {for (int i = 0; i < tabs.size(); ++i) if (tabs[i].name == n) return i; return -1;}
|
||||
int tabIndex(const QString & n) const {
|
||||
for (int i = 0; i < tabs.size(); ++i)
|
||||
if (tabs[i].name == n) return i;
|
||||
return -1;
|
||||
}
|
||||
const QString & toBin(const void * d, int s);
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
QString numIntString(T v, Formats f, int bits = 0) {
|
||||
if (f.testFlag(QPIConsole::Hex)) return "0x" + QString::number(v, 16).toUpper();
|
||||
if (f.testFlag(QPIConsole::Dec)) return QString::number(v);
|
||||
@@ -137,14 +157,14 @@ private:
|
||||
if (f.testFlag(QPIConsole::Bin)) return toBin(&v, bits);
|
||||
return QString::number(v);
|
||||
}
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
QString numFloatString(T v, Formats f) {
|
||||
if (f.testFlag(QPIConsole::Scientific)) return QString::number(v, 'E', 5);
|
||||
return QString::number(v);
|
||||
}
|
||||
|
||||
|
||||
struct QAD_WIDGETS_EXPORT Variable {
|
||||
Variable() {label = widget = 0;}
|
||||
Variable() { label = widget = 0; }
|
||||
QString name;
|
||||
Formats format;
|
||||
int type;
|
||||
@@ -153,24 +173,40 @@ private:
|
||||
const void * ptr;
|
||||
QLabel * label;
|
||||
QLabel * widget;
|
||||
void operator =(const Variable & src) {name = src.name; format = src.format; type = src.type;
|
||||
bitFrom = src.bitFrom; bitCount = src.bitCount; ptr = src.ptr;}
|
||||
void operator=(const Variable & src) {
|
||||
name = src.name;
|
||||
format = src.format;
|
||||
type = src.type;
|
||||
bitFrom = src.bitFrom;
|
||||
bitCount = src.bitCount;
|
||||
ptr = src.ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct QAD_WIDGETS_EXPORT Column {
|
||||
Column(Qt::Alignment align = Qt::AlignRight) {variables.reserve(16); alignment = align;}
|
||||
Column(Qt::Alignment align = Qt::AlignRight) {
|
||||
variables.reserve(16);
|
||||
alignment = align;
|
||||
}
|
||||
QVector<Variable> variables;
|
||||
Qt::Alignment alignment;
|
||||
QFormLayout * layout;
|
||||
int size() const {return variables.size();}
|
||||
Variable & operator [](int index) {return variables[index];}
|
||||
const Variable & operator [](int index) const {return variables[index];}
|
||||
void push_back(const Variable & v) {variables.push_back(v);}
|
||||
void operator =(const Column & src) {variables = src.variables; alignment = src.alignment;}
|
||||
int size() const { return variables.size(); }
|
||||
Variable & operator[](int index) { return variables[index]; }
|
||||
const Variable & operator[](int index) const { return variables[index]; }
|
||||
void push_back(const Variable & v) { variables.push_back(v); }
|
||||
void operator=(const Column & src) {
|
||||
variables = src.variables;
|
||||
alignment = src.alignment;
|
||||
}
|
||||
};
|
||||
|
||||
struct QAD_WIDGETS_EXPORT Tab {
|
||||
Tab(QString n = "", char k = 0) {columns.reserve(16); name = n; key = k;}
|
||||
Tab(QString n = "", char k = 0) {
|
||||
columns.reserve(16);
|
||||
name = n;
|
||||
key = k;
|
||||
}
|
||||
QVector<Column> columns;
|
||||
QString name;
|
||||
char key;
|
||||
@@ -178,22 +214,27 @@ private:
|
||||
QLabel * widget;
|
||||
};
|
||||
|
||||
QVector<Column> & columns() {return tabs[cur_tab].columns;}
|
||||
Column & column(int index) {return tabs[cur_tab].columns[index - 1];}
|
||||
QVector<Column> & columns() { return tabs[cur_tab].columns; }
|
||||
Column & column(int index) { return tabs[cur_tab].columns[index - 1]; }
|
||||
|
||||
Qt::Alignment def_align;
|
||||
QVector<Tab> tabs;
|
||||
QString binstr;
|
||||
Variable tv;
|
||||
int cur_tab, timer;
|
||||
|
||||
private slots:
|
||||
void tabChanged(int tab) {cur_tab = tab;}
|
||||
|
||||
public slots:
|
||||
void start(float freq = 40) {if (timer >= 0) killTimer(timer); timer = startTimer(freq > 0. ? 1000 / freq : 25);}
|
||||
void stop() {if (timer >= 0) killTimer(timer); timer = -1;}
|
||||
|
||||
private slots:
|
||||
void tabChanged(int tab) { cur_tab = tab; }
|
||||
|
||||
public slots:
|
||||
void start(float freq = 40) {
|
||||
if (timer >= 0) killTimer(timer);
|
||||
timer = startTimer(freq > 0. ? 1000 / freq : 25);
|
||||
}
|
||||
void stop() {
|
||||
if (timer >= 0) killTimer(timer);
|
||||
timer = -1;
|
||||
}
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QPIConsole::Formats)
|
||||
|
||||
@@ -32,8 +32,8 @@ QPIEvaluatorContent::QPIEvaluatorContent() {
|
||||
addFunction("rad", 1);
|
||||
addFunction("deg", 1);
|
||||
clearCustomVariables();
|
||||
//addVariable("n", 0.);
|
||||
//addVariable("x1", 123);
|
||||
// addVariable("n", 0.);
|
||||
// addVariable("x1", 123);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,18 +64,18 @@ void QPIEvaluatorContent::clearCustomVariables() {
|
||||
|
||||
void QPIEvaluatorContent::sortVariables() {
|
||||
var_index.clear();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(variables.begin(), variables.end());
|
||||
(variables.begin(), variables.end());
|
||||
for (int i = 0; i < variables.size(); i++)
|
||||
var_index[variables[i].name] = i;
|
||||
/*
|
||||
qDebug() << "---";
|
||||
for (int i = 0; i < variables.size(); i++) {
|
||||
qDebug() << variables[i].name;
|
||||
qDebug() << variables[i].name;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -120,8 +120,10 @@ const QString & QPIEvaluator::prepare(const QString & string) {
|
||||
replaceOperators();
|
||||
removeSpaces();
|
||||
checkBrackets();
|
||||
while (fillElements()) checkBrackets();
|
||||
while (setSignes()) fillElements();
|
||||
while (fillElements())
|
||||
checkBrackets();
|
||||
while (setSignes())
|
||||
fillElements();
|
||||
removeJunk();
|
||||
findUnknownVariables();
|
||||
return currentString;
|
||||
@@ -159,7 +161,8 @@ void QPIEvaluator::removeJunk() {
|
||||
elements.pop_back();
|
||||
junk = true;
|
||||
break;
|
||||
} else break;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +192,8 @@ void QPIEvaluator::findUnknownVariables() {
|
||||
QString cvar;
|
||||
unknownVars.clear();
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
if (elements[i].var_num == -666) cvar += currentString[i];
|
||||
if (elements[i].var_num == -666)
|
||||
cvar += currentString[i];
|
||||
else {
|
||||
if (cvar.length() == 0) continue;
|
||||
unknownVars << cvar;
|
||||
@@ -202,13 +206,8 @@ void QPIEvaluator::findUnknownVariables() {
|
||||
|
||||
|
||||
bool QPIEvaluator::isSign(const QChar & ch) {
|
||||
return ch == '+' || ch == '-' ||
|
||||
ch == '*' || ch == '/' ||
|
||||
ch == '%' || ch == '^' ||
|
||||
ch == '=' || ch == ':' ||
|
||||
ch == '>' || ch == '<' ||
|
||||
ch == '}' || ch == '{' ||
|
||||
ch == '&' || ch == '|';
|
||||
return ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%' || ch == '^' || ch == '=' || ch == ':' || ch == '>' || ch == '<' ||
|
||||
ch == '}' || ch == '{' || ch == '&' || ch == '|';
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +225,8 @@ void QPIEvaluator::checkBrackets() {
|
||||
if (bcnt == 0) {
|
||||
currentString.insert(bpos + inserted, "(");
|
||||
inserted++;
|
||||
} else bcnt--;
|
||||
} else
|
||||
bcnt--;
|
||||
}
|
||||
}
|
||||
if (bcnt > 0) currentString += QString(bcnt, ')');
|
||||
@@ -234,9 +234,8 @@ void QPIEvaluator::checkBrackets() {
|
||||
for (int i = 0; i < tmps.length() - 1; i++) {
|
||||
fc = tmps[i].toLower();
|
||||
sc = tmps[i + 1].toLower();
|
||||
if ((fc == ')' && sc == '(') ||
|
||||
(fc == ')' && sc >= '0' && sc <= '9') ||
|
||||
(fc == ')' && sc >= 'a' && sc <= 'z') ) tmps.insert(++i, '*');
|
||||
if ((fc == ')' && sc == '(') || (fc == ')' && sc >= '0' && sc <= '9') || (fc == ')' && sc >= 'a' && sc <= 'z'))
|
||||
tmps.insert(++i, '*');
|
||||
}
|
||||
currentString = tmps;
|
||||
}
|
||||
@@ -244,26 +243,26 @@ void QPIEvaluator::checkBrackets() {
|
||||
|
||||
bool QPIEvaluator::fillElements() {
|
||||
int fstart, flen, cnum = 0, cpart = 0, cfunc;
|
||||
QChar cc, nc, pc, fc = '!';
|
||||
QChar cc, nc, pc, fc = '!';
|
||||
bool numFound = false;
|
||||
QString curfind, tmps = currentString;
|
||||
elements.resize(tmps.length());
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
elements[i].type = QPIEvaluatorTypes::etVariable;
|
||||
elements[i].type = QPIEvaluatorTypes::etVariable;
|
||||
elements[i].var_num = -666;
|
||||
}
|
||||
currentVariables.clear();
|
||||
//qDebug().nospace() << "search for functions ...";
|
||||
// qDebug().nospace() << "search for functions ...";
|
||||
for (int i = 0; i < content.functionsCount(); i++) {
|
||||
curfind = content.function(i).identifier;
|
||||
cfunc = i; //(int)content.function(i).type;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
cfunc = i; //(int)content.function(i).type;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
while (fstart >= 0) {
|
||||
fstart = tmps.indexOf(curfind, fstart);
|
||||
if (fstart < 0) break;
|
||||
if (tmps[fstart + flen] != '(') {
|
||||
//currentString.insert(fstart + flen, "(");
|
||||
// currentString.insert(fstart + flen, "(");
|
||||
fstart++;
|
||||
continue;
|
||||
}
|
||||
@@ -275,11 +274,11 @@ bool QPIEvaluator::fillElements() {
|
||||
}
|
||||
}
|
||||
cnum = 0;
|
||||
//qDebug().nospace() << "search for variables ...";
|
||||
// qDebug().nospace() << "search for variables ...";
|
||||
for (int i = 0; i < content.variablesCount(); i++) {
|
||||
curfind = content.variable(i).name;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
flen = curfind.length();
|
||||
fstart = 0;
|
||||
while (fstart >= 0) {
|
||||
fstart = tmps.indexOf(curfind, fstart);
|
||||
if (fstart < 0) break;
|
||||
@@ -291,19 +290,19 @@ bool QPIEvaluator::fillElements() {
|
||||
}
|
||||
}
|
||||
curfind = "";
|
||||
cnum = 1;
|
||||
//qDebug().nospace() << "search for numbers ...";
|
||||
cnum = 1;
|
||||
// qDebug().nospace() << "search for numbers ...";
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
cc = tmps[i];
|
||||
/*if (cc == " " || cc == "(" || cc == ")") {
|
||||
curfind = "";
|
||||
cpart = 0;
|
||||
numFound = false;
|
||||
continue;
|
||||
curfind = "";
|
||||
cpart = 0;
|
||||
numFound = false;
|
||||
continue;
|
||||
}*/
|
||||
switch (cpart) {
|
||||
case 0:
|
||||
if ((cc >= '0' && cc <= '9')) {// || cc == '-' || cc == '+') {
|
||||
if ((cc >= '0' && cc <= '9')) { // || cc == '-' || cc == '+') {
|
||||
curfind += cc;
|
||||
cpart = 1;
|
||||
continue;
|
||||
@@ -365,7 +364,7 @@ bool QPIEvaluator::fillElements() {
|
||||
break;
|
||||
}
|
||||
if (numFound) {
|
||||
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
// qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
currentVariables.push_back(QPIEvaluatorTypes::Variable("tmp" + QString::number(cnum), curfind.toDouble()));
|
||||
for (int j = i - curfind.length(); j < i; j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etNumber, cnum, -cnum);
|
||||
@@ -373,12 +372,12 @@ bool QPIEvaluator::fillElements() {
|
||||
}
|
||||
curfind = "";
|
||||
cnum++;
|
||||
cpart = 0;
|
||||
cpart = 0;
|
||||
numFound = false;
|
||||
}
|
||||
}
|
||||
if (cpart > 0) {
|
||||
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
// qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
|
||||
currentVariables.push_back(QPIEvaluatorTypes::Variable("tmp" + QString::number(cnum), curfind.toDouble()));
|
||||
for (int j = tmps.length() - curfind.length(); j < tmps.length(); j++) {
|
||||
elements[j].set(QPIEvaluatorTypes::etNumber, cnum, -cnum);
|
||||
@@ -386,30 +385,34 @@ bool QPIEvaluator::fillElements() {
|
||||
}
|
||||
}
|
||||
cc = nc = fc;
|
||||
//qDebug().nospace() << "search for signes ...";
|
||||
// qDebug().nospace() << "search for signes ...";
|
||||
for (int i = 0; i < tmps.length(); i++) {
|
||||
cc = tmps[i];
|
||||
if (i > 0) pc = tmps[i - 1];
|
||||
else pc = fc;
|
||||
if (i < tmps.length() - 1) nc = tmps[i + 1];
|
||||
else nc = fc;
|
||||
if (i > 0)
|
||||
pc = tmps[i - 1];
|
||||
else
|
||||
pc = fc;
|
||||
if (i < tmps.length() - 1)
|
||||
nc = tmps[i + 1];
|
||||
else
|
||||
nc = fc;
|
||||
if (cc == '(' || cc == ')' || cc == ',') {
|
||||
elements[i].set(QPIEvaluatorTypes::etOperator, -1);
|
||||
continue;
|
||||
}
|
||||
if (cc == '-' || cc == '+') {
|
||||
elements[i].set(QPIEvaluatorTypes::etOperator, -1);
|
||||
if (i < tmps.length() - 1) if (elements[i + 1].type == QPIEvaluatorTypes::etVariable ||
|
||||
elements[i + 1].type == QPIEvaluatorTypes::etFunction) continue;
|
||||
if (i < tmps.length() - 1)
|
||||
if (elements[i + 1].type == QPIEvaluatorTypes::etVariable || elements[i + 1].type == QPIEvaluatorTypes::etFunction)
|
||||
continue;
|
||||
if ((pc == '(' || isSign(pc) || i == 0) && i < tmps.length() - 1) {
|
||||
if (elements[i + 1].type != QPIEvaluatorTypes::etOperator) {
|
||||
cnum = elements[i + 1].num;
|
||||
elements[i].set(QPIEvaluatorTypes::etNumber, cnum);
|
||||
tmps.replace(i, 1, fc);
|
||||
///cout << "found sign " << cc << " :" << cnum - 1 << endl;
|
||||
if (cc == '-' && currentVariables.size() >= cnum)
|
||||
currentVariables[cnum - 1].value = -currentVariables[cnum - 1].value;
|
||||
//i++;
|
||||
/// cout << "found sign " << cc << " :" << cnum - 1 << endl;
|
||||
if (cc == '-' && currentVariables.size() >= cnum) currentVariables[cnum - 1].value = -currentVariables[cnum - 1].value;
|
||||
// i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -423,17 +426,17 @@ bool QPIEvaluator::fillElements() {
|
||||
qDebug().nospace() << tmps;
|
||||
cout << " ";
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
*/
|
||||
return false;
|
||||
//for (int i = 0; i < currentVariables.size(); i++) qDebug() << "var " << i << ": " << currentVariables[i].value.real();
|
||||
// for (int i = 0; i < currentVariables.size(); i++) qDebug() << "var " << i << ": " << currentVariables[i].value.real();
|
||||
}
|
||||
|
||||
|
||||
@@ -443,29 +446,45 @@ bool QPIEvaluator::setSignes() {
|
||||
QString tmps = currentString;
|
||||
for (int i = 0; i < tmps.length() - 1; i++) {
|
||||
needInsert = 0;
|
||||
ni = i + 1;
|
||||
ni = i + 1;
|
||||
if (i > 0) pi = i - 1;
|
||||
fc = tmps[i].toLower();
|
||||
sc = tmps[ni].toLower();
|
||||
pc = tmps[pi].toLower();
|
||||
//if (elements[i].type == etOperator || elements[ni].type == etVariable) continue;
|
||||
// if (elements[i].type == etOperator || elements[ni].type == etVariable) continue;
|
||||
if (fc == ',' || sc == ',') continue;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etOperator && elements[ni].type == QPIEvaluatorTypes::etOperator) continue;
|
||||
if (fc == ')' && (elements[ni].type == QPIEvaluatorTypes::etNumber || elements[ni].type == QPIEvaluatorTypes::etVariable || elements[ni].type == QPIEvaluatorTypes::etFunction)) needInsert = 1;
|
||||
if (sc == '(' && (elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable)) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etNumber && elements[i].num != elements[ni].num) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etVariable && elements[i].num != elements[ni].num) needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etVariable) || (elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etNumber)) needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable) && elements[ni].type == QPIEvaluatorTypes::etFunction) needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type == QPIEvaluatorTypes::etFunction && elements[i].num != elements[ni].num) needInsert = 2;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type != QPIEvaluatorTypes::etFunction && sc != '(') needInsert = 2;
|
||||
if (elements[pi].type == QPIEvaluatorTypes::etOperator && (elements[ni].type == QPIEvaluatorTypes::etFunction || elements[ni].type == QPIEvaluatorTypes::etVariable) && fc == '-') needInsert = 3;
|
||||
if (fc == ')' && (elements[ni].type == QPIEvaluatorTypes::etNumber || elements[ni].type == QPIEvaluatorTypes::etVariable ||
|
||||
elements[ni].type == QPIEvaluatorTypes::etFunction))
|
||||
needInsert = 1;
|
||||
if (sc == '(' && (elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable))
|
||||
needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etNumber &&
|
||||
elements[i].num != elements[ni].num)
|
||||
needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etVariable &&
|
||||
elements[i].num != elements[ni].num)
|
||||
needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber && elements[ni].type == QPIEvaluatorTypes::etVariable) ||
|
||||
(elements[i].type == QPIEvaluatorTypes::etVariable && elements[ni].type == QPIEvaluatorTypes::etNumber))
|
||||
needInsert = 1;
|
||||
if ((elements[i].type == QPIEvaluatorTypes::etNumber || elements[i].type == QPIEvaluatorTypes::etVariable) &&
|
||||
elements[ni].type == QPIEvaluatorTypes::etFunction)
|
||||
needInsert = 1;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type == QPIEvaluatorTypes::etFunction &&
|
||||
elements[i].num != elements[ni].num)
|
||||
needInsert = 2;
|
||||
if (elements[i].type == QPIEvaluatorTypes::etFunction && elements[ni].type != QPIEvaluatorTypes::etFunction && sc != '(')
|
||||
needInsert = 2;
|
||||
if (elements[pi].type == QPIEvaluatorTypes::etOperator &&
|
||||
(elements[ni].type == QPIEvaluatorTypes::etFunction || elements[ni].type == QPIEvaluatorTypes::etVariable) && fc == '-')
|
||||
needInsert = 3;
|
||||
switch (needInsert) {
|
||||
case 1:
|
||||
currentString.insert(ni + inserted, "*");
|
||||
elements.insert(ni + inserted, QPIEvaluatorTypes::Element(QPIEvaluatorTypes::etOperator, -1));
|
||||
//inserted++;
|
||||
//i++;
|
||||
// inserted++;
|
||||
// i++;
|
||||
return true;
|
||||
/*case 2:
|
||||
currentString.insert(ni + inserted, ")");
|
||||
@@ -478,17 +497,17 @@ bool QPIEvaluator::setSignes() {
|
||||
case 3:
|
||||
currentString.insert(ni + inserted, "1*");
|
||||
elements.insert(ni + inserted, QPIEvaluatorTypes::Element(QPIEvaluatorTypes::etOperator, -1));
|
||||
//inserted;
|
||||
//i++;
|
||||
// inserted;
|
||||
// i++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*if (elements[tmps.length() - 1].type == etFunction) {
|
||||
currentString.insert(tmps.length() + inserted, ")");
|
||||
currentString.insert(tmps.length() + inserted, "(");
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
return true;
|
||||
currentString.insert(tmps.length() + inserted, ")");
|
||||
currentString.insert(tmps.length() + inserted, "(");
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
|
||||
return true;
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
@@ -507,8 +526,9 @@ void QPIEvaluator::convert() {
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
for (int k = i + 1; k < j; k++)
|
||||
elements.remove(i);
|
||||
// i++;
|
||||
}
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
pe = elements[i];
|
||||
@@ -520,8 +540,9 @@ void QPIEvaluator::convert() {
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
for (int k = i + 1; k < j; k++)
|
||||
elements.remove(i);
|
||||
// i++;
|
||||
}
|
||||
for (int i = 0; i < currentString.length(); i++) {
|
||||
pe = elements[i];
|
||||
@@ -533,33 +554,33 @@ void QPIEvaluator::convert() {
|
||||
j++;
|
||||
}
|
||||
currentString.replace(i, j - i, " ");
|
||||
for (int k = i + 1; k < j; k++) elements.remove(i);
|
||||
//i++;
|
||||
for (int k = i + 1; k < j; k++)
|
||||
elements.remove(i);
|
||||
// i++;
|
||||
}
|
||||
/*qDebug().nospace() << currentString;
|
||||
cout << " ";
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
switch (elements[i].type) {
|
||||
case etFunction: cout << "f"; break;
|
||||
case etNumber: cout << "n"; break;
|
||||
case etOperator: cout << "o"; break;
|
||||
case etVariable: cout << "v"; break;
|
||||
}
|
||||
}
|
||||
cout << endl;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
const QString & QPIEvaluator::preprocess(const QString & string) {
|
||||
static QString ret;
|
||||
int lind;
|
||||
ret = prepare(string);
|
||||
convert();
|
||||
instructions.clear();
|
||||
//qDebug() << preproc->currentString;
|
||||
// qDebug() << preproc->currentString;
|
||||
variables = currentVariables;
|
||||
lind = parse(currentString);
|
||||
lind = parse(currentString);
|
||||
if (instructions.size() == 0) {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable());
|
||||
instructions.push_back(QPIEvaluatorTypes::Instruction(QPIEvaluatorTypes::oNone, QVector<int>(1, lind), -variables.size()));
|
||||
@@ -568,17 +589,17 @@ const QString & QPIEvaluator::preprocess(const QString & string) {
|
||||
/*
|
||||
cout << endl << "variables:" << endl;
|
||||
for (int i = 0; i < variables.size(); i++)
|
||||
cout << i << " value = " << variables[i].value << endl;
|
||||
cout << i << " value = " << variables[i].value << endl;
|
||||
|
||||
cout << endl << "instructions:" << endl;
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
cout << i << endl;
|
||||
cout << " operation " << instructions[i].operation << endl;
|
||||
cout << " operators: ";
|
||||
for (int j = 0; j < instructions[i].operators.size(); j++)
|
||||
cout << instructions[i].operators[j] << "; ";
|
||||
cout << endl << " function " << instructions[i].function << endl;
|
||||
cout << " out " << instructions[i].out << endl;
|
||||
cout << i << endl;
|
||||
cout << " operation " << instructions[i].operation << endl;
|
||||
cout << " operators: ";
|
||||
for (int j = 0; j < instructions[i].operators.size(); j++)
|
||||
cout << instructions[i].operators[j] << "; ";
|
||||
cout << endl << " function " << instructions[i].function << endl;
|
||||
cout << " out " << instructions[i].out << endl;
|
||||
}
|
||||
*/
|
||||
makeOutput(ret);
|
||||
@@ -616,53 +637,51 @@ int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
QVector<int> args, atmp;
|
||||
QVector<QPIEvaluatorTypes::Operation> opers;
|
||||
|
||||
///qDebug() << "to parse :" + string;
|
||||
///cout << " "; for (int i = 0; i < slen; i++) cout << preproc->elements[i + offset].type; cout << endl;
|
||||
/// qDebug() << "to parse :" + string;
|
||||
/// cout << " "; for (int i = 0; i < slen; i++) cout << preproc->elements[i + offset].type; cout << endl;
|
||||
|
||||
for (int i = 0; i < slen; i++) {
|
||||
ce = elements[i + offset];
|
||||
cc = string[i];
|
||||
switch (ce.type) {
|
||||
case QPIEvaluatorTypes::etNumber:
|
||||
args.push_back(ce.var_num);
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etVariable:
|
||||
args.push_back(ce.var_num);
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etNumber: args.push_back(ce.var_num); continue;
|
||||
case QPIEvaluatorTypes::etVariable: args.push_back(ce.var_num); continue;
|
||||
case QPIEvaluatorTypes::etFunction:
|
||||
i++;
|
||||
cfunc = content.function(ce.var_num);
|
||||
//facnt = cfunc.arguments;
|
||||
// facnt = cfunc.arguments;
|
||||
atmp.clear();
|
||||
bcnt = farg = 1;
|
||||
///qDebug() << "function: " + cfunc.identifier;
|
||||
//for (int k = 0; k < facnt; k++) {
|
||||
carg = "";
|
||||
k = i + 1;
|
||||
//if (string.size() <= k || k < 0) return -666;
|
||||
/// qDebug() << "function: " + cfunc.identifier;
|
||||
// for (int k = 0; k < facnt; k++) {
|
||||
carg = "";
|
||||
k = i + 1;
|
||||
// if (string.size() <= k || k < 0) return -666;
|
||||
while (bcnt > 0) {
|
||||
//if (k < facnt - 1) fcomma = string.indexOf(',', j);
|
||||
// if (k < facnt - 1) fcomma = string.indexOf(',', j);
|
||||
cc = string[k];
|
||||
switch (cc.toLatin1()) {
|
||||
case '(': bcnt++; break;
|
||||
case ')':
|
||||
bcnt--;
|
||||
if (bcnt == 0) {
|
||||
///qDebug() << "arument: " << carg;
|
||||
/// qDebug() << "arument: " << carg;
|
||||
atmp.push_back(parse(carg, k + offset - carg.length()));
|
||||
k++;
|
||||
carg = "";
|
||||
if (atmp.size() > 0) if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
if (atmp.size() > 0)
|
||||
if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (bcnt == 1) {
|
||||
///qDebug() << "arument: " << carg;
|
||||
/// qDebug() << "arument: " << carg;
|
||||
atmp.push_back(parse(carg, k + offset - carg.length()));
|
||||
k++;
|
||||
carg = "";
|
||||
if (atmp.size() > 0) if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
if (atmp.size() > 0)
|
||||
if (atmp.back() < 0 && farg > 0) farg = atmp.back();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -677,31 +696,73 @@ int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
}
|
||||
instructions.push_back(QPIEvaluatorTypes::Instruction(QPIEvaluatorTypes::oFunction, atmp, farg, ce.var_num));
|
||||
args.push_back(farg);
|
||||
//for (int i = 0; i < args.size(); i++) cout << preproc->currentVariables[-args[i]].value << endl;
|
||||
//i = j + 1;
|
||||
// for (int i = 0; i < args.size(); i++) cout << preproc->currentVariables[-args[i]].value << endl;
|
||||
// i = j + 1;
|
||||
continue;
|
||||
case QPIEvaluatorTypes::etOperator:
|
||||
//qDebug() << "operator: " << cc;
|
||||
// qDebug() << "operator: " << cc;
|
||||
if (cc == '(') {
|
||||
sbrackets = inBrackets(string.right(slen - i));
|
||||
args.push_back(parse(sbrackets, i + offset + 1));
|
||||
i += sbrackets.length() + 1;
|
||||
continue;
|
||||
}
|
||||
if (cc == '+') {opers.push_back(QPIEvaluatorTypes::oAdd); continue;}
|
||||
if (cc == '-') {opers.push_back(QPIEvaluatorTypes::oSubtract); continue;}
|
||||
if (cc == '*') {opers.push_back(QPIEvaluatorTypes::oMultiply); continue;}
|
||||
if (cc == '/') {opers.push_back(QPIEvaluatorTypes::oDivide); continue;}
|
||||
if (cc == '%') {opers.push_back(QPIEvaluatorTypes::oResidue); continue;}
|
||||
if (cc == '^') {opers.push_back(QPIEvaluatorTypes::oPower); continue;}
|
||||
if (cc == '=') {opers.push_back(QPIEvaluatorTypes::oEqual); continue;}
|
||||
if (cc == ':') {opers.push_back(QPIEvaluatorTypes::oNotEqual); continue;}
|
||||
if (cc == '}') {opers.push_back(QPIEvaluatorTypes::oGreaterEqual); continue;}
|
||||
if (cc == '{') {opers.push_back(QPIEvaluatorTypes::oSmallerEqual); continue;}
|
||||
if (cc == '>') {opers.push_back(QPIEvaluatorTypes::oGreater); continue;}
|
||||
if (cc == '<') {opers.push_back(QPIEvaluatorTypes::oSmaller); continue;}
|
||||
if (cc == '&') {opers.push_back(QPIEvaluatorTypes::oAnd); continue;}
|
||||
if (cc == '|') {opers.push_back(QPIEvaluatorTypes::oOr); continue;}
|
||||
if (cc == '+') {
|
||||
opers.push_back(QPIEvaluatorTypes::oAdd);
|
||||
continue;
|
||||
}
|
||||
if (cc == '-') {
|
||||
opers.push_back(QPIEvaluatorTypes::oSubtract);
|
||||
continue;
|
||||
}
|
||||
if (cc == '*') {
|
||||
opers.push_back(QPIEvaluatorTypes::oMultiply);
|
||||
continue;
|
||||
}
|
||||
if (cc == '/') {
|
||||
opers.push_back(QPIEvaluatorTypes::oDivide);
|
||||
continue;
|
||||
}
|
||||
if (cc == '%') {
|
||||
opers.push_back(QPIEvaluatorTypes::oResidue);
|
||||
continue;
|
||||
}
|
||||
if (cc == '^') {
|
||||
opers.push_back(QPIEvaluatorTypes::oPower);
|
||||
continue;
|
||||
}
|
||||
if (cc == '=') {
|
||||
opers.push_back(QPIEvaluatorTypes::oEqual);
|
||||
continue;
|
||||
}
|
||||
if (cc == ':') {
|
||||
opers.push_back(QPIEvaluatorTypes::oNotEqual);
|
||||
continue;
|
||||
}
|
||||
if (cc == '}') {
|
||||
opers.push_back(QPIEvaluatorTypes::oGreaterEqual);
|
||||
continue;
|
||||
}
|
||||
if (cc == '{') {
|
||||
opers.push_back(QPIEvaluatorTypes::oSmallerEqual);
|
||||
continue;
|
||||
}
|
||||
if (cc == '>') {
|
||||
opers.push_back(QPIEvaluatorTypes::oGreater);
|
||||
continue;
|
||||
}
|
||||
if (cc == '<') {
|
||||
opers.push_back(QPIEvaluatorTypes::oSmaller);
|
||||
continue;
|
||||
}
|
||||
if (cc == '&') {
|
||||
opers.push_back(QPIEvaluatorTypes::oAnd);
|
||||
continue;
|
||||
}
|
||||
if (cc == '|') {
|
||||
opers.push_back(QPIEvaluatorTypes::oOr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -711,25 +772,33 @@ int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
for (int i = 0; i < opers.size(); i++) cout << opers[i] << ", ";
|
||||
*/
|
||||
if (opers.size() == 0) {
|
||||
if (args.size() > 0) return args.back();
|
||||
else return -666;
|
||||
if (args.size() > 0)
|
||||
return args.back();
|
||||
else
|
||||
return -666;
|
||||
}
|
||||
int oprior = -1;
|
||||
QVector<QPIEvaluatorTypes::Operation> opv;
|
||||
while(1) {
|
||||
while (1) {
|
||||
operationsByPriority(++oprior, opv);
|
||||
if (opv.isEmpty()) break;
|
||||
for (int j = 0; j < opers.size(); j++) {
|
||||
if (!opv.contains(opers[j])) continue;
|
||||
atmp.clear();
|
||||
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
|
||||
else atmp.push_back(-666);
|
||||
if (j + 1 < args.size() && j >= -1) atmp.push_back(args[j + 1]);
|
||||
else atmp.push_back(-666);
|
||||
if (j < args.size() && j >= 0)
|
||||
atmp.push_back(args[j]);
|
||||
else
|
||||
atmp.push_back(-666);
|
||||
if (j + 1 < args.size() && j >= -1)
|
||||
atmp.push_back(args[j + 1]);
|
||||
else
|
||||
atmp.push_back(-666);
|
||||
farg = 1;
|
||||
if (atmp[0] < 0) farg = atmp[0];
|
||||
if (atmp[0] < 0)
|
||||
farg = atmp[0];
|
||||
else {
|
||||
if (atmp[1] < 0) farg = atmp[1];
|
||||
if (atmp[1] < 0)
|
||||
farg = atmp[1];
|
||||
else {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable());
|
||||
farg = -variables.size();
|
||||
@@ -745,7 +814,7 @@ int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
}
|
||||
}
|
||||
return instructions.back().out;
|
||||
///cout << endl;
|
||||
/// cout << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -758,7 +827,7 @@ bool QPIEvaluator::check() {
|
||||
}
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
error = false;
|
||||
ci = instructions[i];
|
||||
ci = instructions[i];
|
||||
switch (ci.operation) {
|
||||
case QPIEvaluatorTypes::oNone: break;
|
||||
case QPIEvaluatorTypes::oFunction:
|
||||
@@ -838,9 +907,10 @@ void QPIEvaluator::operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operat
|
||||
case 0: ret << QPIEvaluatorTypes::oPower; break;
|
||||
case 1: ret << QPIEvaluatorTypes::oMultiply << QPIEvaluatorTypes::oDivide << QPIEvaluatorTypes::oResidue; break;
|
||||
case 2: ret << QPIEvaluatorTypes::oAdd << QPIEvaluatorTypes::oSubtract; break;
|
||||
case 3: ret << QPIEvaluatorTypes::oEqual << QPIEvaluatorTypes::oNotEqual
|
||||
<< QPIEvaluatorTypes::oGreaterEqual << QPIEvaluatorTypes::oSmallerEqual
|
||||
<< QPIEvaluatorTypes::oGreater << QPIEvaluatorTypes::oSmaller; break;
|
||||
case 3:
|
||||
ret << QPIEvaluatorTypes::oEqual << QPIEvaluatorTypes::oNotEqual << QPIEvaluatorTypes::oGreaterEqual
|
||||
<< QPIEvaluatorTypes::oSmallerEqual << QPIEvaluatorTypes::oGreater << QPIEvaluatorTypes::oSmaller;
|
||||
break;
|
||||
case 4: ret << QPIEvaluatorTypes::oAnd; break;
|
||||
case 5: ret << QPIEvaluatorTypes::oOr; break;
|
||||
default: break;
|
||||
@@ -858,105 +928,63 @@ inline complexd QPIEvaluator::residue(const complexd & f, const complexd & s) {
|
||||
|
||||
inline void QPIEvaluator::execFunction(const QPIEvaluatorTypes::Instruction & ci) {
|
||||
QPIEvaluatorTypes::Function cfunc = content.function(ci.function);
|
||||
int oi = -ci.out - 1;
|
||||
int oi = -ci.out - 1;
|
||||
complexd tmp, stmp;
|
||||
double ldtmp;
|
||||
//qDebug() << "function " << (int)cfunc.type;
|
||||
// qDebug() << "function " << (int)cfunc.type;
|
||||
switch (cfunc.type) {
|
||||
case QPIEvaluatorTypes::bfSin:
|
||||
tmpvars[oi].value = sin(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCos:
|
||||
tmpvars[oi].value = cos(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfTg:
|
||||
tmpvars[oi].value = tan(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSin: tmpvars[oi].value = sin(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfCos: tmpvars[oi].value = cos(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfTg: tmpvars[oi].value = tan(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfCtg:
|
||||
tmp = tan(value(ci.operators[0]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArcsin:
|
||||
tmpvars[oi].value = asinc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArccos:
|
||||
tmpvars[oi].value = acosc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArctg:
|
||||
tmpvars[oi].value = atanc_qpie(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArcctg:
|
||||
tmpvars[oi].value = atanc_qpie(-value(ci.operators[0])) + M_PI_2;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSh:
|
||||
tmpvars[oi].value = sinh(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfCh:
|
||||
tmpvars[oi].value = cosh(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfTh:
|
||||
tmpvars[oi].value = tanh(value(ci.operators[0]));
|
||||
if (tmp == complexd_0)
|
||||
tmpvars[oi].value = 0.;
|
||||
else
|
||||
tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArcsin: tmpvars[oi].value = asinc_qpie(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfArccos: tmpvars[oi].value = acosc_qpie(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfArctg: tmpvars[oi].value = atanc_qpie(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfArcctg: tmpvars[oi].value = atanc_qpie(-value(ci.operators[0])) + M_PI_2; break;
|
||||
case QPIEvaluatorTypes::bfSh: tmpvars[oi].value = sinh(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfCh: tmpvars[oi].value = cosh(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfTh: tmpvars[oi].value = tanh(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfCth:
|
||||
tmp = tanh(value(ci.operators[0]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfAbs:
|
||||
tmpvars[oi].value = abs(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSqrt:
|
||||
tmpvars[oi].value = sqrt(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfSqr:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[0]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfExp:
|
||||
tmpvars[oi].value = exp(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfPow:
|
||||
tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLn:
|
||||
tmpvars[oi].value = log(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLg:
|
||||
tmpvars[oi].value = log10(value(ci.operators[0]));
|
||||
if (tmp == complexd_0)
|
||||
tmpvars[oi].value = 0.;
|
||||
else
|
||||
tmpvars[oi].value = complexd_1 / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfAbs: tmpvars[oi].value = abs(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfSqrt: tmpvars[oi].value = sqrt(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfSqr: tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[0]); break;
|
||||
case QPIEvaluatorTypes::bfExp: tmpvars[oi].value = exp(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfPow: tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1])); break;
|
||||
case QPIEvaluatorTypes::bfLn: tmpvars[oi].value = log(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfLg: tmpvars[oi].value = log10(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfLog:
|
||||
tmp = log(value(ci.operators[1]));
|
||||
if (tmp == complexd_0) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = log(value(ci.operators[0])) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRe:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfIm:
|
||||
tmpvars[oi].value = value(ci.operators[0]).imag();
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfArg:
|
||||
tmpvars[oi].value = arg(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfLen:
|
||||
tmpvars[oi].value = abs(value(ci.operators[0]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfConj:
|
||||
tmpvars[oi].value = conj(value(ci.operators[0]));
|
||||
if (tmp == complexd_0)
|
||||
tmpvars[oi].value = 0.;
|
||||
else
|
||||
tmpvars[oi].value = log(value(ci.operators[0])) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRe: tmpvars[oi].value = value(ci.operators[0]).real(); break;
|
||||
case QPIEvaluatorTypes::bfIm: tmpvars[oi].value = value(ci.operators[0]).imag(); break;
|
||||
case QPIEvaluatorTypes::bfArg: tmpvars[oi].value = arg(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfLen: tmpvars[oi].value = abs(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfConj: tmpvars[oi].value = conj(value(ci.operators[0])); break;
|
||||
case QPIEvaluatorTypes::bfSign:
|
||||
ldtmp = value(ci.operators[0]).real();
|
||||
ldtmp = value(ci.operators[0]).real();
|
||||
tmpvars[oi].value = ldtmp >= 0. ? complexd_1 : -complexd_1;
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRad:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * complexd(deg2rad_qpie, 0.);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfDeg:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * complexd(rad2deg_qpie, 0.);
|
||||
break;
|
||||
case QPIEvaluatorTypes::bfRad: tmpvars[oi].value = value(ci.operators[0]) * complexd(deg2rad_qpie, 0.); break;
|
||||
case QPIEvaluatorTypes::bfDeg: tmpvars[oi].value = value(ci.operators[0]) * complexd(rad2deg_qpie, 0.); break;
|
||||
case QPIEvaluatorTypes::bfRandom:
|
||||
tmp = static_cast<double>(rand()) / RAND_MAX;
|
||||
stmp = value(ci.operators[1]) - value(ci.operators[0]);
|
||||
tmp = static_cast<double>(rand()) / RAND_MAX;
|
||||
stmp = value(ci.operators[1]) - value(ci.operators[0]);
|
||||
tmpvars[oi].value = value(ci.operators[0]) + tmp * stmp;
|
||||
break;
|
||||
default: break;
|
||||
@@ -969,75 +997,45 @@ inline bool QPIEvaluator::execInstructions() {
|
||||
int oi;
|
||||
complexd tmp;
|
||||
tmpvars = variables;
|
||||
//cout << "var count " << tmpvars.size() << endl;
|
||||
// cout << "var count " << tmpvars.size() << endl;
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
ci = instructions[i];
|
||||
oi = -ci.out - 1;
|
||||
//cout << value(ci.operators[0]) << operationChar(ci.operation) << value(ci.operators[1]) << ", " << oi << endl;
|
||||
// cout << value(ci.operators[0]) << operationChar(ci.operation) << value(ci.operators[1]) << ", " << oi << endl;
|
||||
switch (ci.operation) {
|
||||
case QPIEvaluatorTypes::oAdd:
|
||||
tmpvars[oi].value = value(ci.operators[0]) + value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSubtract:
|
||||
tmpvars[oi].value = value(ci.operators[0]) - value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oMultiply:
|
||||
tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oAdd: tmpvars[oi].value = value(ci.operators[0]) + value(ci.operators[1]); break;
|
||||
case QPIEvaluatorTypes::oSubtract: tmpvars[oi].value = value(ci.operators[0]) - value(ci.operators[1]); break;
|
||||
case QPIEvaluatorTypes::oMultiply: tmpvars[oi].value = value(ci.operators[0]) * value(ci.operators[1]); break;
|
||||
case QPIEvaluatorTypes::oDivide:
|
||||
tmp = value(ci.operators[1]);
|
||||
if (tmp == complexd(0., 0.)) tmpvars[oi].value = 0.;
|
||||
else tmpvars[oi].value = value(ci.operators[0]) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oResidue:
|
||||
tmpvars[oi].value = residue(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::oPower:
|
||||
tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1]));
|
||||
break;
|
||||
case QPIEvaluatorTypes::oEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]) == value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oNotEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]) != value(ci.operators[1]);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oGreaterEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() >= value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSmallerEqual:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() <= value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oGreater:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oSmaller:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() < value(ci.operators[1]).real();
|
||||
break;
|
||||
case QPIEvaluatorTypes::oAnd:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > 0. && value(ci.operators[1]).real() > 0.;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oOr:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() > 0. || value(ci.operators[1]).real() > 0.;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oFunction:
|
||||
execFunction(ci);
|
||||
break;
|
||||
case QPIEvaluatorTypes::oNone:
|
||||
tmpvars[oi].value = value(ci.operators[0]);
|
||||
if (tmp == complexd(0., 0.))
|
||||
tmpvars[oi].value = 0.;
|
||||
else
|
||||
tmpvars[oi].value = value(ci.operators[0]) / tmp;
|
||||
break;
|
||||
case QPIEvaluatorTypes::oResidue: tmpvars[oi].value = residue(value(ci.operators[0]), value(ci.operators[1])); break;
|
||||
case QPIEvaluatorTypes::oPower: tmpvars[oi].value = pow(value(ci.operators[0]), value(ci.operators[1])); break;
|
||||
case QPIEvaluatorTypes::oEqual: tmpvars[oi].value = value(ci.operators[0]) == value(ci.operators[1]); break;
|
||||
case QPIEvaluatorTypes::oNotEqual: tmpvars[oi].value = value(ci.operators[0]) != value(ci.operators[1]); break;
|
||||
case QPIEvaluatorTypes::oGreaterEqual: tmpvars[oi].value = value(ci.operators[0]).real() >= value(ci.operators[1]).real(); break;
|
||||
case QPIEvaluatorTypes::oSmallerEqual: tmpvars[oi].value = value(ci.operators[0]).real() <= value(ci.operators[1]).real(); break;
|
||||
case QPIEvaluatorTypes::oGreater: tmpvars[oi].value = value(ci.operators[0]).real() > value(ci.operators[1]).real(); break;
|
||||
case QPIEvaluatorTypes::oSmaller: tmpvars[oi].value = value(ci.operators[0]).real() < value(ci.operators[1]).real(); break;
|
||||
case QPIEvaluatorTypes::oAnd: tmpvars[oi].value = value(ci.operators[0]).real() > 0. && value(ci.operators[1]).real() > 0.; break;
|
||||
case QPIEvaluatorTypes::oOr: tmpvars[oi].value = value(ci.operators[0]).real() > 0. || value(ci.operators[1]).real() > 0.; break;
|
||||
case QPIEvaluatorTypes::oFunction: execFunction(ci); break;
|
||||
case QPIEvaluatorTypes::oNone: tmpvars[oi].value = value(ci.operators[0]); break;
|
||||
}
|
||||
}
|
||||
if (!instructions.isEmpty())
|
||||
out = value(instructions.back().out);
|
||||
if (!instructions.isEmpty()) out = value(instructions.back().out);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool QPIEvaluator::check(const QString & string) {
|
||||
currentString = preprocess(string);
|
||||
correct = check();
|
||||
if (!correct)
|
||||
return false;
|
||||
correct = check();
|
||||
if (!correct) return false;
|
||||
lastError = "Correct";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPIEVALUATOR_P_H
|
||||
#define QPIEVALUATOR_P_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
|
||||
|
||||
#ifndef PIP_MATH_COMPLEX
|
||||
#define QPIEVALUATOR_COMPLEX
|
||||
# define QPIEVALUATOR_COMPLEX
|
||||
typedef std::complex<double> complexd;
|
||||
const complexd complexd_i(0., 1.);
|
||||
const complexd complexd_0(0.);
|
||||
@@ -38,100 +38,194 @@ const complexd complexd_1(1.);
|
||||
const double deg2rad_qpie = atan(1.) / 45.;
|
||||
const double rad2deg_qpie = 45. / atan(1.);
|
||||
|
||||
inline complexd round_qpie(const complexd & c) {return complexd(round(c.real()), round(c.imag()));}
|
||||
inline complexd floor_qpie(const complexd & c) {return complexd(floor(c.real()), floor(c.imag()));}
|
||||
inline complexd ceil_qpie(const complexd & c) {return complexd(ceil(c.real()), ceil(c.imag()));}
|
||||
inline complexd round_qpie(const complexd & c) {
|
||||
return complexd(round(c.real()), round(c.imag()));
|
||||
}
|
||||
inline complexd floor_qpie(const complexd & c) {
|
||||
return complexd(floor(c.real()), floor(c.imag()));
|
||||
}
|
||||
inline complexd ceil_qpie(const complexd & c) {
|
||||
return complexd(ceil(c.real()), ceil(c.imag()));
|
||||
}
|
||||
#if (__cplusplus >= 201103L) // стандарт C++ 11 или выше
|
||||
# define acosc_qpie acos
|
||||
# define asinc_qpie asin
|
||||
# define atanc_qpie atan
|
||||
#else
|
||||
inline complexd atanc_qpie(const complexd & c) {return complexd(0., 0.5) * log((complexd_1 - complexd_i * c) / (complexd_1 + complexd_i * c));}
|
||||
inline complexd asinc_qpie(const complexd & c) {return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));}
|
||||
inline complexd acosc_qpie(const complexd & c) {return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));}
|
||||
inline complexd atanc_qpie(const complexd & c) {
|
||||
return complexd(0., 0.5) * log((complexd_1 - complexd_i * c) / (complexd_1 + complexd_i * c));
|
||||
}
|
||||
inline complexd asinc_qpie(const complexd & c) {
|
||||
return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));
|
||||
}
|
||||
inline complexd acosc_qpie(const complexd & c) {
|
||||
return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace QPIEvaluatorTypes {
|
||||
static const int operationCount = 14;
|
||||
static const int operationCount = 14;
|
||||
|
||||
enum eType {etNumber, etOperator, etVariable, etFunction};
|
||||
enum Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower,
|
||||
oEqual, oNotEqual, oGreater, oSmaller, oGreaterEqual, oSmallerEqual,
|
||||
oAnd, oOr, oFunction};
|
||||
enum BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg,
|
||||
bfArcsin, bfArccos, bfArctg, bfArcctg,
|
||||
bfExp, bfRandom, bfSh, bfCh, bfTh, bfCth,
|
||||
bfSqrt, bfSqr, bfPow, bfAbs,
|
||||
bfLn, bfLg, bfLog, bfSign,
|
||||
bfIm, bfRe, bfArg, bfLen, bfConj,
|
||||
bfRad, bfDeg};
|
||||
enum eType {
|
||||
etNumber,
|
||||
etOperator,
|
||||
etVariable,
|
||||
etFunction
|
||||
};
|
||||
enum Operation {
|
||||
oNone,
|
||||
oAdd,
|
||||
oSubtract,
|
||||
oMultiply,
|
||||
oDivide,
|
||||
oResidue,
|
||||
oPower,
|
||||
oEqual,
|
||||
oNotEqual,
|
||||
oGreater,
|
||||
oSmaller,
|
||||
oGreaterEqual,
|
||||
oSmallerEqual,
|
||||
oAnd,
|
||||
oOr,
|
||||
oFunction
|
||||
};
|
||||
enum BaseFunctions {
|
||||
bfUnknown,
|
||||
bfSin,
|
||||
bfCos,
|
||||
bfTg,
|
||||
bfCtg,
|
||||
bfArcsin,
|
||||
bfArccos,
|
||||
bfArctg,
|
||||
bfArcctg,
|
||||
bfExp,
|
||||
bfRandom,
|
||||
bfSh,
|
||||
bfCh,
|
||||
bfTh,
|
||||
bfCth,
|
||||
bfSqrt,
|
||||
bfSqr,
|
||||
bfPow,
|
||||
bfAbs,
|
||||
bfLn,
|
||||
bfLg,
|
||||
bfLog,
|
||||
bfSign,
|
||||
bfIm,
|
||||
bfRe,
|
||||
bfArg,
|
||||
bfLen,
|
||||
bfConj,
|
||||
bfRad,
|
||||
bfDeg
|
||||
};
|
||||
|
||||
struct Instruction {
|
||||
Instruction() {;}
|
||||
Instruction(Operation oper, QVector<int> opers, int out_ind, int func = -1) {
|
||||
operation = oper; operators = opers; out = out_ind; function = func;}
|
||||
Operation operation;
|
||||
QVector<int> operators;
|
||||
int out;
|
||||
int function;};
|
||||
struct Element {
|
||||
Element() {;}
|
||||
Element(eType new_type, int new_num, int new_var_num = -1) {set(new_type, new_num, new_var_num);}
|
||||
void set(eType new_type, int new_num, int new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;}
|
||||
eType type;
|
||||
int num;
|
||||
int var_num;};
|
||||
struct Function {
|
||||
Function() {arguments = 0; type = bfUnknown;}
|
||||
Function(const QString & name, int args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype;}
|
||||
QString identifier;
|
||||
BaseFunctions type;
|
||||
int arguments;};
|
||||
struct Variable {
|
||||
Variable() {value = 0.;}
|
||||
Variable(const QString & var_name, complexd val) {name = var_name; value = val;}
|
||||
QString name;
|
||||
complexd value;};
|
||||
inline bool operator <(const Variable & s1, const Variable & s2) {
|
||||
if (s1.name.size() != s2.name.size())
|
||||
return s1.name.size() > s2.name.size();
|
||||
return s1.name > s2.name;
|
||||
struct Instruction {
|
||||
Instruction() { ; }
|
||||
Instruction(Operation oper, QVector<int> opers, int out_ind, int func = -1) {
|
||||
operation = oper;
|
||||
operators = opers;
|
||||
out = out_ind;
|
||||
function = func;
|
||||
}
|
||||
Operation operation;
|
||||
QVector<int> operators;
|
||||
int out;
|
||||
int function;
|
||||
};
|
||||
struct Element {
|
||||
Element() { ; }
|
||||
Element(eType new_type, int new_num, int new_var_num = -1) { set(new_type, new_num, new_var_num); }
|
||||
void set(eType new_type, int new_num, int new_var_num = -1) {
|
||||
type = new_type;
|
||||
num = new_num;
|
||||
var_num = new_var_num;
|
||||
}
|
||||
eType type;
|
||||
int num;
|
||||
int var_num;
|
||||
};
|
||||
struct Function {
|
||||
Function() {
|
||||
arguments = 0;
|
||||
type = bfUnknown;
|
||||
}
|
||||
Function(const QString & name, int args, BaseFunctions ftype) {
|
||||
identifier = name;
|
||||
arguments = args;
|
||||
type = ftype;
|
||||
}
|
||||
QString identifier;
|
||||
BaseFunctions type;
|
||||
int arguments;
|
||||
};
|
||||
struct Variable {
|
||||
Variable() { value = 0.; }
|
||||
Variable(const QString & var_name, complexd val) {
|
||||
name = var_name;
|
||||
value = val;
|
||||
}
|
||||
QString name;
|
||||
complexd value;
|
||||
};
|
||||
inline bool operator<(const Variable & s1, const Variable & s2) {
|
||||
if (s1.name.size() != s2.name.size()) return s1.name.size() > s2.name.size();
|
||||
return s1.name > s2.name;
|
||||
}
|
||||
} // namespace QPIEvaluatorTypes
|
||||
|
||||
|
||||
/*
|
||||
≠ :
|
||||
≥ }
|
||||
≤ {
|
||||
⋀ &
|
||||
⋁ |
|
||||
≠ :
|
||||
≥ }
|
||||
≤ {
|
||||
⋀ &
|
||||
⋁ |
|
||||
*/
|
||||
class QPIEvaluatorContent
|
||||
{
|
||||
class QPIEvaluatorContent {
|
||||
friend class QPIEvaluator;
|
||||
|
||||
public:
|
||||
QPIEvaluatorContent();
|
||||
~QPIEvaluatorContent() {;}
|
||||
~QPIEvaluatorContent() { ; }
|
||||
|
||||
void addFunction(const QString & name, int args = 1) {functions.push_back(QPIEvaluatorTypes::Function(name, args, getBaseFunction(name)));}
|
||||
void addVariable(const QString & name, const complexd & val = 0., bool sort = true) {variables.push_back(QPIEvaluatorTypes::Variable(name, val)); if (sort) sortVariables();}
|
||||
int functionsCount() const {return functions.size();}
|
||||
int variablesCount() const {return variables.size();}
|
||||
int customVariablesCount() const {return variables.size() - cv_count;}
|
||||
int findFunction(const QString & name) const {return func_index.value(name, -1);}
|
||||
int findVariable(const QString & name) const {return var_index.value(name, -1);}
|
||||
QPIEvaluatorTypes::Function function(int index) {if (index < 0 || index >= functions.size()) return QPIEvaluatorTypes::Function(); return functions[index];}
|
||||
QPIEvaluatorTypes::Variable variable(int index) {if (index < 0 || index >= variables.size()) return QPIEvaluatorTypes::Variable(); return variables[index];}
|
||||
QPIEvaluatorTypes::Function function(const QString & name) {return function(findFunction(name));}
|
||||
QPIEvaluatorTypes::Variable variable(const QString & name) {return variable(findVariable(name));}
|
||||
QPIEvaluatorTypes::Variable customVariable(int index) {if (index < cv_count || index >= variables.size() + cv_count) return QPIEvaluatorTypes::Variable(); return variables[index + cv_count];}
|
||||
void addFunction(const QString & name, int args = 1) {
|
||||
functions.push_back(QPIEvaluatorTypes::Function(name, args, getBaseFunction(name)));
|
||||
}
|
||||
void addVariable(const QString & name, const complexd & val = 0., bool sort = true) {
|
||||
variables.push_back(QPIEvaluatorTypes::Variable(name, val));
|
||||
if (sort) sortVariables();
|
||||
}
|
||||
int functionsCount() const { return functions.size(); }
|
||||
int variablesCount() const { return variables.size(); }
|
||||
int customVariablesCount() const { return variables.size() - cv_count; }
|
||||
int findFunction(const QString & name) const { return func_index.value(name, -1); }
|
||||
int findVariable(const QString & name) const { return var_index.value(name, -1); }
|
||||
QPIEvaluatorTypes::Function function(int index) {
|
||||
if (index < 0 || index >= functions.size()) return QPIEvaluatorTypes::Function();
|
||||
return functions[index];
|
||||
}
|
||||
QPIEvaluatorTypes::Variable variable(int index) {
|
||||
if (index < 0 || index >= variables.size()) return QPIEvaluatorTypes::Variable();
|
||||
return variables[index];
|
||||
}
|
||||
QPIEvaluatorTypes::Function function(const QString & name) { return function(findFunction(name)); }
|
||||
QPIEvaluatorTypes::Variable variable(const QString & name) { return variable(findVariable(name)); }
|
||||
QPIEvaluatorTypes::Variable customVariable(int index) {
|
||||
if (index < cv_count || index >= variables.size() + cv_count) return QPIEvaluatorTypes::Variable();
|
||||
return variables[index + cv_count];
|
||||
}
|
||||
bool setVariableValue(int index, complexd new_value);
|
||||
bool setVariableName(int index, const QString & new_name);
|
||||
bool setVariableValue(const QString & var_name, const complexd & new_value) {return setVariableValue(findVariable(var_name), new_value);}
|
||||
bool setVariableName(const QString & var_name, const QString & new_name) {return setVariableName(findVariable(var_name), new_name);}
|
||||
void removeVariable(int index) {variables.remove(index);}
|
||||
void removeVariable(const QString & var_name) {removeVariable(findVariable(var_name));}
|
||||
bool setVariableValue(const QString & var_name, const complexd & new_value) {
|
||||
return setVariableValue(findVariable(var_name), new_value);
|
||||
}
|
||||
bool setVariableName(const QString & var_name, const QString & new_name) { return setVariableName(findVariable(var_name), new_name); }
|
||||
void removeVariable(int index) { variables.remove(index); }
|
||||
void removeVariable(const QString & var_name) { removeVariable(findVariable(var_name)); }
|
||||
void clearCustomVariables();
|
||||
void sortVariables();
|
||||
QPIEvaluatorTypes::BaseFunctions getBaseFunction(const QString & name);
|
||||
@@ -141,29 +235,29 @@ private:
|
||||
QVector<QPIEvaluatorTypes::Variable> variables;
|
||||
QMap<QString, int> var_index, func_index;
|
||||
int cv_count;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class QPIEvaluator
|
||||
{
|
||||
class QPIEvaluator {
|
||||
public:
|
||||
QPIEvaluator() {correct = false ;}
|
||||
~QPIEvaluator() {;}
|
||||
QPIEvaluator() { correct = false; }
|
||||
~QPIEvaluator() { ; }
|
||||
|
||||
bool check(const QString & string);
|
||||
bool isCorrect() const {return correct;}
|
||||
bool isCorrect() const { return correct; }
|
||||
int setVariable(const QString & name, complexd value = 0.);
|
||||
void setVariable(int index, complexd value = 0.) {if (index >= 0 && index < content.variablesCount()) content.setVariableValue(index, value);}
|
||||
void setCustomVariableValue(int index, complexd value = 0.) {content.variables[index + content.cv_count].value = value;}
|
||||
void setVariable(int index, complexd value = 0.) {
|
||||
if (index >= 0 && index < content.variablesCount()) content.setVariableValue(index, value);
|
||||
}
|
||||
void setCustomVariableValue(int index, complexd value = 0.) { content.variables[index + content.cv_count].value = value; }
|
||||
complexd evaluate();
|
||||
void removeVariable(const QString & name) {content.removeVariable(name);}
|
||||
void clearCustomVariables() {content.clearCustomVariables();}
|
||||
int variableIndex(const QString & name) const {return content.findVariable(name);}
|
||||
const QStringList & unknownVariables() const {return unknownVars;}
|
||||
const QString & expression() const {return currentString;}
|
||||
const QString & error() const {return lastError;}
|
||||
const complexd & lastResult() const {return out;}
|
||||
void removeVariable(const QString & name) { content.removeVariable(name); }
|
||||
void clearCustomVariables() { content.clearCustomVariables(); }
|
||||
int variableIndex(const QString & name) const { return content.findVariable(name); }
|
||||
const QStringList & unknownVariables() const { return unknownVars; }
|
||||
const QString & expression() const { return currentString; }
|
||||
const QString & error() const { return lastError; }
|
||||
const complexd & lastResult() const { return out; }
|
||||
static QString inBrackets(const QString & string);
|
||||
|
||||
QPIEvaluatorContent content;
|
||||
@@ -182,28 +276,42 @@ private:
|
||||
bool fillElements();
|
||||
bool setSignes();
|
||||
bool isSign(const QChar & ch);
|
||||
QString inverse(const QString & string) {int len = string.length(); QString s; for (int i = 0; i < len; i++) s += string[len - i - 1]; return s;}
|
||||
QString inverse(const QString & string) {
|
||||
int len = string.length();
|
||||
QString s;
|
||||
for (int i = 0; i < len; i++)
|
||||
s += string[len - i - 1];
|
||||
return s;
|
||||
}
|
||||
bool check();
|
||||
bool execInstructions();
|
||||
QString operationChar(const QPIEvaluatorTypes::Operation & operation);
|
||||
void operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operation> & ret);
|
||||
QPIEvaluatorTypes::Operation operationInOrder(const int & index);
|
||||
complexd value(const int & index) {if (index < 0) return tmpvars[-index - 1].value; else return kvars->at(index).value;}
|
||||
complexd value(const int & index) {
|
||||
if (index < 0)
|
||||
return tmpvars[-index - 1].value;
|
||||
else
|
||||
return kvars->at(index).value;
|
||||
}
|
||||
inline complexd residue(const complexd & f, const complexd & s);
|
||||
inline void execFunction(const QPIEvaluatorTypes::Instruction & ci);
|
||||
|
||||
QVector<QPIEvaluatorTypes::Element> elements;
|
||||
QVector<QPIEvaluatorTypes::Variable> currentVariables, variables, tmpvars, * kvars;
|
||||
QVector<QPIEvaluatorTypes::Variable> currentVariables, variables, tmpvars, *kvars;
|
||||
QVector<QPIEvaluatorTypes::Instruction> instructions;
|
||||
QStringList unknownVars;
|
||||
QString currentString, lastError;
|
||||
complexd out;
|
||||
bool correct;
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline bool operator ==(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);}
|
||||
inline bool operator !=(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);}
|
||||
inline bool operator==(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {
|
||||
return (e1.type == e2.type && e1.num == e2.num);
|
||||
}
|
||||
inline bool operator!=(QPIEvaluatorTypes::Element e1, QPIEvaluatorTypes::Element e2) {
|
||||
return (e1.type != e2.type || e1.num != e2.num);
|
||||
}
|
||||
|
||||
#endif // QPIEVALUATOR_P_H
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "qpointedit.h"
|
||||
|
||||
#include "float.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,62 +1,71 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPOINTEDIT_H
|
||||
#define QPOINTEDIT_H
|
||||
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QEvent>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
|
||||
class QAD_WIDGETS_EXPORT QPointEdit: public QWidget
|
||||
{
|
||||
|
||||
class QAD_WIDGETS_EXPORT QPointEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF value READ value WRITE setValue)
|
||||
Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
|
||||
|
||||
|
||||
public:
|
||||
explicit QPointEdit(QWidget * parent = 0);
|
||||
~QPointEdit() {delete s_x; delete s_y; delete lbl;}
|
||||
|
||||
QPointF value() const {return QPointF(s_x->value(), s_y->value());}
|
||||
int decimals() const {return s_x->decimals();}
|
||||
|
||||
~QPointEdit() {
|
||||
delete s_x;
|
||||
delete s_y;
|
||||
delete lbl;
|
||||
}
|
||||
|
||||
QPointF value() const { return QPointF(s_x->value(), s_y->value()); }
|
||||
int decimals() const { return s_x->decimals(); }
|
||||
|
||||
public slots:
|
||||
void setValue(QPointF v) {s_x->setValue(v.x()); s_y->setValue(v.y());}
|
||||
void setDecimals(int d) {s_x->setDecimals(d); s_y->setDecimals(d);}
|
||||
|
||||
void setValue(QPointF v) {
|
||||
s_x->setValue(v.x());
|
||||
s_y->setValue(v.y());
|
||||
}
|
||||
void setDecimals(int d) {
|
||||
s_x->setDecimals(d);
|
||||
s_y->setDecimals(d);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void changeEvent(QEvent * e);
|
||||
|
||||
|
||||
QBoxLayout lay;
|
||||
QDoubleSpinBox * s_x, * s_y;
|
||||
QDoubleSpinBox *s_x, *s_y;
|
||||
QLabel * lbl;
|
||||
|
||||
|
||||
private slots:
|
||||
void changed() {emit valueChanged(QPointF(s_x->value(), s_y->value()));}
|
||||
|
||||
void changed() { emit valueChanged(QPointF(s_x->value(), s_y->value())); }
|
||||
|
||||
signals:
|
||||
void valueChanged(QPointF);
|
||||
|
||||
};
|
||||
|
||||
#endif // QPOINTEDIT_H
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "qrectedit.h"
|
||||
|
||||
#include "float.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QRECTEDIT_H
|
||||
#define QRECTEDIT_H
|
||||
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QEvent>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
|
||||
class QAD_WIDGETS_EXPORT QRectEdit: public QWidget
|
||||
{
|
||||
|
||||
class QAD_WIDGETS_EXPORT QRectEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRectF value READ value WRITE setValue)
|
||||
Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
|
||||
@@ -38,34 +38,66 @@ class QAD_WIDGETS_EXPORT QRectEdit: public QWidget
|
||||
|
||||
public:
|
||||
explicit QRectEdit(QWidget * parent = 0);
|
||||
~QRectEdit() {delete s_x; delete s_y; delete s_w; delete s_h; delete lbl_0; delete lbl_1; delete lbl_2;}
|
||||
|
||||
QRectF value() const {return QRectF(s_x->value(), s_y->value(), s_w->value(), s_h->value());}
|
||||
int decimals() const {return s_x->decimals();}
|
||||
double maximum() const {return s_x->maximum();}
|
||||
double minimum() const {return s_x->minimum();}
|
||||
double singleStep() const {return s_x->singleStep();}
|
||||
~QRectEdit() {
|
||||
delete s_x;
|
||||
delete s_y;
|
||||
delete s_w;
|
||||
delete s_h;
|
||||
delete lbl_0;
|
||||
delete lbl_1;
|
||||
delete lbl_2;
|
||||
}
|
||||
|
||||
QRectF value() const { return QRectF(s_x->value(), s_y->value(), s_w->value(), s_h->value()); }
|
||||
int decimals() const { return s_x->decimals(); }
|
||||
double maximum() const { return s_x->maximum(); }
|
||||
double minimum() const { return s_x->minimum(); }
|
||||
double singleStep() const { return s_x->singleStep(); }
|
||||
|
||||
public slots:
|
||||
void setValue(QRectF v) {s_x->setValue(v.x()); s_y->setValue(v.y()); s_w->setValue(v.width()); s_h->setValue(v.height());}
|
||||
void setDecimals(int d) {s_x->setDecimals(d); s_y->setDecimals(d); s_w->setDecimals(d); s_h->setDecimals(d);}
|
||||
void setMaximum(double m) {s_x->setMaximum(m); s_y->setMaximum(m); s_w->setMaximum(m); s_h->setMaximum(m);}
|
||||
void setMinimum(double m) {s_x->setMinimum(m); s_y->setMinimum(m); s_w->setMinimum(m); s_h->setMinimum(m);}
|
||||
void setSingleStep(double m) {s_x->setSingleStep(m); s_y->setSingleStep(m); s_w->setSingleStep(m); s_h->setSingleStep(m);}
|
||||
void setValue(QRectF v) {
|
||||
s_x->setValue(v.x());
|
||||
s_y->setValue(v.y());
|
||||
s_w->setValue(v.width());
|
||||
s_h->setValue(v.height());
|
||||
}
|
||||
void setDecimals(int d) {
|
||||
s_x->setDecimals(d);
|
||||
s_y->setDecimals(d);
|
||||
s_w->setDecimals(d);
|
||||
s_h->setDecimals(d);
|
||||
}
|
||||
void setMaximum(double m) {
|
||||
s_x->setMaximum(m);
|
||||
s_y->setMaximum(m);
|
||||
s_w->setMaximum(m);
|
||||
s_h->setMaximum(m);
|
||||
}
|
||||
void setMinimum(double m) {
|
||||
s_x->setMinimum(m);
|
||||
s_y->setMinimum(m);
|
||||
s_w->setMinimum(m);
|
||||
s_h->setMinimum(m);
|
||||
}
|
||||
void setSingleStep(double m) {
|
||||
s_x->setSingleStep(m);
|
||||
s_y->setSingleStep(m);
|
||||
s_w->setSingleStep(m);
|
||||
s_h->setSingleStep(m);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void changeEvent(QEvent * e);
|
||||
|
||||
|
||||
QBoxLayout lay;
|
||||
QDoubleSpinBox * s_x, * s_y, * s_w, * s_h;
|
||||
QLabel * lbl_0, * lbl_1, * lbl_2;
|
||||
|
||||
QDoubleSpinBox *s_x, *s_y, *s_w, *s_h;
|
||||
QLabel *lbl_0, *lbl_1, *lbl_2;
|
||||
|
||||
private slots:
|
||||
void changed() {emit valueChanged(QRectF(s_x->value(), s_y->value(), s_w->value(), s_h->value()));}
|
||||
|
||||
void changed() { emit valueChanged(QRectF(s_x->value(), s_y->value(), s_w->value(), s_h->value())); }
|
||||
|
||||
signals:
|
||||
void valueChanged(QRectF);
|
||||
|
||||
};
|
||||
|
||||
#endif // QRECTEDIT_H
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "qvariantedit.h"
|
||||
|
||||
#include <QDateTimeEdit>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -6,7 +7,8 @@
|
||||
|
||||
QStringList StringListEdit::value() const {
|
||||
QStringList l;
|
||||
for (int i = 0; i < combo->count(); ++i) l << combo->itemText(i);
|
||||
for (int i = 0; i < combo->count(); ++i)
|
||||
l << combo->itemText(i);
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -46,14 +48,14 @@ void StringListEdit::clear() {
|
||||
|
||||
|
||||
StringListEdit::StringListEdit(QWidget * parent): QWidget(parent) {
|
||||
lay = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
lay = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
combo = new EComboBox(this);
|
||||
combo->setEditable(true);
|
||||
combo->setLineEdit(new CLineEdit);
|
||||
combo->setInsertPolicy(QComboBox::NoInsert);
|
||||
butt_apply = new QPushButton(this);
|
||||
butt_add = new QPushButton(this);
|
||||
butt_del = new QPushButton(this);
|
||||
butt_add = new QPushButton(this);
|
||||
butt_del = new QPushButton(this);
|
||||
butt_clear = new QPushButton(this);
|
||||
butt_apply->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_add->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
@@ -80,8 +82,9 @@ StringListEdit::StringListEdit(QWidget * parent): QWidget(parent) {
|
||||
connect(butt_apply, SIGNAL(clicked(bool)), this, SLOT(editItem()));
|
||||
connect(butt_add, SIGNAL(clicked(bool)), this, SLOT(addItem()));
|
||||
connect(butt_del, SIGNAL(clicked(bool)), this, SLOT(delItem()));
|
||||
connect(butt_clear, &QPushButton::clicked, [this](){
|
||||
if (QMessageBox::question(this, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) clear();
|
||||
connect(butt_clear, &QPushButton::clicked, [this]() {
|
||||
if (QMessageBox::question(this, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,13 +108,11 @@ void StringListEdit::editItem() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PathEdit::PathEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
|
||||
is_dir = is_abs = is_save = false;
|
||||
filter = tr("All files(*)");
|
||||
line = new CLineEdit(this);
|
||||
butt_select = new QPushButton(this);
|
||||
filter = tr("All files(*)");
|
||||
line = new CLineEdit(this);
|
||||
butt_select = new QPushButton(this);
|
||||
butt_select->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_select->setIcon(QIcon(":/icons/document-open.png"));
|
||||
butt_select->setToolTip(tr("Choose") + " ...");
|
||||
@@ -134,7 +135,6 @@ void PathEdit::changeEvent(QEvent * e) {
|
||||
|
||||
void PathEdit::resizeEvent(QResizeEvent *) {
|
||||
butt_select->setMaximumHeight(line->height());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ void PathEdit::setValue(const QString & v) {
|
||||
|
||||
void PathEdit::select() {
|
||||
QString ret;
|
||||
if (is_dir) ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), value());
|
||||
if (is_dir)
|
||||
ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), value());
|
||||
else {
|
||||
if (is_save)
|
||||
ret = QFileDialog::getSaveFileName(this, tr("Select file"), value(), filter);
|
||||
@@ -157,31 +158,28 @@ void PathEdit::select() {
|
||||
ret = QFileDialog::getOpenFileName(this, tr("Select file"), value(), filter);
|
||||
}
|
||||
if (ret.isEmpty()) return;
|
||||
if (!is_abs)
|
||||
ret = QDir::current().relativeFilePath(ret);
|
||||
if (!is_abs) ret = QDir::current().relativeFilePath(ret);
|
||||
line->setText(ret);
|
||||
emit valueChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVariantEdit::QVariantEdit(QWidget * parent): QWidget(parent) {
|
||||
setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom =_cur_edit = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom = _cur_edit = 0;
|
||||
_recreate(QVariant());
|
||||
}
|
||||
|
||||
@@ -277,7 +275,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::Double:
|
||||
#endif
|
||||
_espin = new EvalSpinBox(this);
|
||||
_espin = new EvalSpinBox(this);
|
||||
_cur_edit = _espin;
|
||||
connect(_espin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -296,7 +294,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QString:
|
||||
#endif
|
||||
_line = new CLineEdit(this);
|
||||
_line = new CLineEdit(this);
|
||||
_cur_edit = _line;
|
||||
connect(_line, SIGNAL(textChanged(QString)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -305,7 +303,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QStringList:
|
||||
#endif
|
||||
_list = new StringListEdit(this);
|
||||
_list = new StringListEdit(this);
|
||||
_cur_edit = _list;
|
||||
connect(_list, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -354,7 +352,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QDate:
|
||||
#endif
|
||||
_date = new QDateEdit(this);
|
||||
_date = new QDateEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -363,7 +361,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QTime:
|
||||
#endif
|
||||
_date = new QTimeEdit(this);
|
||||
_date = new QTimeEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -372,7 +370,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QDateTime:
|
||||
#endif
|
||||
_date = new QDateTimeEdit(this);
|
||||
_date = new QDateTimeEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -403,7 +401,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
QWidget * fw = f->createEditor();
|
||||
if (fw) {
|
||||
fw->setParent(this);
|
||||
_custom = fw;
|
||||
_custom = fw;
|
||||
_cur_edit = _custom;
|
||||
connect(_custom, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
}
|
||||
@@ -525,15 +523,15 @@ QVariant QVariantEdit::value() const {
|
||||
for (int i = 0; i < _enum->count(); ++i)
|
||||
ret.enum_list << QAD::Enumerator(_enum->itemData(i).toInt(), _enum->itemText(i));
|
||||
ret.enum_name = _enum->property("enum_name").toString();
|
||||
ret.selected = _enum->currentText();
|
||||
ret.selected = _enum->currentText();
|
||||
return QVariant::fromValue<QAD::Enum>(ret);
|
||||
}
|
||||
if (_value.canConvert<QAD::File>() && _path) {
|
||||
if (!_path->is_dir) {
|
||||
QAD::File ret;
|
||||
ret.file = _path->value();
|
||||
ret.filter = _path->filter;
|
||||
ret.is_abs = _path->is_abs;
|
||||
ret.file = _path->value();
|
||||
ret.filter = _path->filter;
|
||||
ret.is_abs = _path->is_abs;
|
||||
ret.is_save = _path->is_save;
|
||||
return QVariant::fromValue<QAD::File>(ret);
|
||||
}
|
||||
@@ -541,7 +539,7 @@ QVariant QVariantEdit::value() const {
|
||||
if (_value.canConvert<QAD::Dir>() && _path) {
|
||||
if (_path->is_dir) {
|
||||
QAD::Dir ret;
|
||||
ret.dir = _path->value();
|
||||
ret.dir = _path->value();
|
||||
ret.is_abs = _path->is_abs;
|
||||
return QVariant::fromValue<QAD::Dir>(ret);
|
||||
}
|
||||
@@ -557,42 +555,66 @@ QVariant QVariantEdit::value() const {
|
||||
void QVariantEdit::setValue(const QVariant & v) {
|
||||
_recreate(v);
|
||||
if (_cur_edit) _cur_edit->blockSignals(true);
|
||||
if (_line) {_line->setText(v.toString());}
|
||||
if (_check) {_check->setChecked(v.toBool()); _check->setText(v.toBool() ? "true" : "false");}
|
||||
if (_color) {_color->setColor(v.value<QColor>());}
|
||||
if (_list) {_list->setValue(v.toStringList());}
|
||||
if (_date) {_date->setDateTime(v.toDateTime());}
|
||||
if (_spin) {_spin->setValue(v.toDouble());}
|
||||
if (_espin) {_espin->setValue(v.toDouble());}
|
||||
if (_rect) {_rect->setValue(v.toRectF());}
|
||||
if (_point) {_point->setValue(v.toPointF());}
|
||||
if (_path) {
|
||||
if (_path->is_dir) _setDir(v.value<QAD::Dir>());
|
||||
else _setFile(v.value<QAD::File>());
|
||||
if (_line) {
|
||||
_line->setText(v.toString());
|
||||
}
|
||||
if (_check) {
|
||||
_check->setChecked(v.toBool());
|
||||
_check->setText(v.toBool() ? "true" : "false");
|
||||
}
|
||||
if (_color) {
|
||||
_color->setColor(v.value<QColor>());
|
||||
}
|
||||
if (_list) {
|
||||
_list->setValue(v.toStringList());
|
||||
}
|
||||
if (_date) {
|
||||
_date->setDateTime(v.toDateTime());
|
||||
}
|
||||
if (_spin) {
|
||||
_spin->setValue(v.toDouble());
|
||||
}
|
||||
if (_espin) {
|
||||
_espin->setValue(v.toDouble());
|
||||
}
|
||||
if (_rect) {
|
||||
_rect->setValue(v.toRectF());
|
||||
}
|
||||
if (_point) {
|
||||
_point->setValue(v.toPointF());
|
||||
}
|
||||
if (_path) {
|
||||
if (_path->is_dir)
|
||||
_setDir(v.value<QAD::Dir>());
|
||||
else
|
||||
_setFile(v.value<QAD::File>());
|
||||
}
|
||||
if (_enum) {
|
||||
_setEnum(v.value<QAD::Enum>());
|
||||
}
|
||||
if (_custom) {
|
||||
_setCustom(v);
|
||||
}
|
||||
if (_enum) {_setEnum(v.value<QAD::Enum>());}
|
||||
if (_custom) {_setCustom(v);}
|
||||
if (_cur_edit) _cur_edit->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
void QVariantEdit::_delete() {
|
||||
if (_cur_edit)
|
||||
delete _cur_edit;
|
||||
if (_cur_edit) delete _cur_edit;
|
||||
_cur_edit = 0;
|
||||
_custom = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -604,9 +626,9 @@ void QVariantEdit::_resize() {
|
||||
|
||||
void QVariantEdit::_newPath() {
|
||||
_delete();
|
||||
_path = new PathEdit(this);
|
||||
_path = new PathEdit(this);
|
||||
_cur_edit = _path;
|
||||
_value = _value.toString();
|
||||
_value = _value.toString();
|
||||
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
_resize();
|
||||
}
|
||||
@@ -615,7 +637,7 @@ void QVariantEdit::_newPath() {
|
||||
void QVariantEdit::_setEnum(const QAD::Enum & v) {
|
||||
_enum->clear();
|
||||
_enum->setProperty("enum_name", v.enum_name);
|
||||
foreach (const QAD::Enumerator & e, v.enum_list)
|
||||
foreach(const QAD::Enumerator & e, v.enum_list)
|
||||
_enum->addItem(e.name, QVariant(e.value));
|
||||
int i(0);
|
||||
for (i = 0; i < _enum->count(); ++i)
|
||||
@@ -623,18 +645,16 @@ void QVariantEdit::_setEnum(const QAD::Enum & v) {
|
||||
_enum->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
if (i == _enum->count())
|
||||
_enum->setCurrentIndex(-1);
|
||||
if (i == _enum->count()) _enum->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
|
||||
void QVariantEdit::_setFile(const QAD::File & v) {
|
||||
_path->is_dir = false;
|
||||
_path->is_dir = false;
|
||||
_path->filter = v.filter;
|
||||
_path->is_abs = v.is_abs;
|
||||
_path->is_save = v.is_save;
|
||||
_path->setValue(v.file);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -654,4 +674,3 @@ void QVariantEdit::_changed() {
|
||||
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
|
||||
emit valueChanged(value());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,120 +1,117 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QVARIANTEDIT_H
|
||||
#define QVARIANTEDIT_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
#include <QDoubleSpinBox>
|
||||
#include "qvariantedit_custom.h"
|
||||
#include "qad_types.h"
|
||||
#include "clineedit.h"
|
||||
#include "ecombobox.h"
|
||||
#include "colorbutton.h"
|
||||
#include "qrectedit.h"
|
||||
#include "qpointedit.h"
|
||||
#include "ecombobox.h"
|
||||
#include "evalspinbox.h"
|
||||
#include "qad_types.h"
|
||||
#include "qad_widgets_export.h"
|
||||
#include "qpointedit.h"
|
||||
#include "qrectedit.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT StringListEdit: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT StringListEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StringListEdit(QWidget * parent = 0);
|
||||
|
||||
|
||||
QStringList value() const;
|
||||
|
||||
|
||||
private:
|
||||
virtual void changeEvent(QEvent * e);
|
||||
|
||||
|
||||
QBoxLayout * lay;
|
||||
EComboBox * combo;
|
||||
QPushButton * butt_apply, * butt_add, * butt_del, * butt_clear;
|
||||
|
||||
QPushButton *butt_apply, *butt_add, *butt_del, *butt_clear;
|
||||
|
||||
public slots:
|
||||
void setValue(const QStringList & v);
|
||||
|
||||
|
||||
private slots:
|
||||
void editItem();
|
||||
void addItem();
|
||||
void delItem();
|
||||
void clear();
|
||||
|
||||
|
||||
signals:
|
||||
void valueChanged();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT PathEdit: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT PathEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PathEdit(QWidget * parent = 0);
|
||||
~PathEdit() {delete line; delete butt_select;}
|
||||
|
||||
QString value() const {return line->text();}
|
||||
|
||||
~PathEdit() {
|
||||
delete line;
|
||||
delete butt_select;
|
||||
}
|
||||
|
||||
QString value() const { return line->text(); }
|
||||
|
||||
bool is_dir, is_abs, is_save;
|
||||
QString filter;
|
||||
|
||||
private:
|
||||
virtual void changeEvent(QEvent * e);
|
||||
virtual void resizeEvent(QResizeEvent * );
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
|
||||
QBoxLayout lay;
|
||||
CLineEdit * line;
|
||||
QPushButton * butt_select;
|
||||
|
||||
|
||||
public slots:
|
||||
void setValue(const QString & v);
|
||||
|
||||
|
||||
private slots:
|
||||
void select();
|
||||
|
||||
|
||||
signals:
|
||||
void valueChanged();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QVariantEdit: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT QVariantEdit: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue)
|
||||
|
||||
|
||||
public:
|
||||
explicit QVariantEdit(QWidget * parent = 0);
|
||||
~QVariantEdit();
|
||||
|
||||
|
||||
QVariant value() const;
|
||||
//QSize sizeHint() const {if (_cur_edit) return _cur_edit->sizeHint(); return QWidget::sizeHint();}
|
||||
//QSize minimumSizeHint() const {if (_cur_edit) return _cur_edit->minimumSizeHint(); return QWidget::minimumSizeHint();}
|
||||
|
||||
// QSize sizeHint() const {if (_cur_edit) return _cur_edit->sizeHint(); return QWidget::sizeHint();}
|
||||
// QSize minimumSizeHint() const {if (_cur_edit) return _cur_edit->minimumSizeHint(); return QWidget::minimumSizeHint();}
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent * );
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
void _recreate(const QVariant & new_value);
|
||||
void _delete();
|
||||
void _resize();
|
||||
@@ -123,8 +120,8 @@ protected:
|
||||
void _setFile(const QAD::File & v);
|
||||
void _setDir(const QAD::Dir & v);
|
||||
void _setCustom(const QVariant & v);
|
||||
|
||||
|
||||
|
||||
|
||||
QLabel * _empty;
|
||||
CLineEdit * _line;
|
||||
QCheckBox * _check;
|
||||
@@ -137,18 +134,17 @@ protected:
|
||||
QPointEdit * _point;
|
||||
PathEdit * _path;
|
||||
EComboBox * _enum;
|
||||
QWidget * _custom, * _cur_edit;
|
||||
QWidget *_custom, *_cur_edit;
|
||||
QVariant _value;
|
||||
|
||||
|
||||
private slots:
|
||||
void _changed();
|
||||
|
||||
|
||||
public slots:
|
||||
void setValue(const QVariant & v);
|
||||
|
||||
|
||||
signals:
|
||||
void valueChanged(QVariant);
|
||||
|
||||
};
|
||||
|
||||
#endif // QVARIANTEDIT_H
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "qvariantedit_custom.h"
|
||||
|
||||
|
||||
QVariantEditorFactories::QVariantEditorFactories() {
|
||||
|
||||
}
|
||||
QVariantEditorFactories::QVariantEditorFactories() {}
|
||||
|
||||
|
||||
QVariantEditorFactories * QVariantEditorFactories::instance() {
|
||||
@@ -19,7 +17,7 @@ void QVariantEditorFactories::registerEditorFactory(int meta_id, QVariantEditorF
|
||||
return;
|
||||
}
|
||||
if (s->factories.contains(meta_id))
|
||||
;//qDebug() << "[QVariantEditorFactories] Warning: factory for metaTypeID" << meta_id << "already registered, override";
|
||||
; // qDebug() << "[QVariantEditorFactories] Warning: factory for metaTypeID" << meta_id << "already registered, override";
|
||||
s->factories[meta_id] = f;
|
||||
}
|
||||
|
||||
@@ -40,4 +38,3 @@ QVariantEditorFactoryBase * QVariantEditorFactories::editorFactory(int meta_id)
|
||||
QVariantEditorFactories * s = QVariantEditorFactories::instance();
|
||||
return s->factories.value(meta_id, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +1,44 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QVARIANTEDIT_CUSTOM_H
|
||||
#define QVARIANTEDIT_CUSTOM_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QVariantEdit;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT QVariantEditorFactoryBase {
|
||||
friend class QVariantEdit;
|
||||
|
||||
public:
|
||||
QVariantEditorFactoryBase() {}
|
||||
virtual ~QVariantEditorFactoryBase() {}
|
||||
virtual QWidget * createEditor() = 0;
|
||||
private:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -51,7 +53,7 @@ private:
|
||||
QVariantEditorFactories();
|
||||
static QVariantEditorFactories * instance();
|
||||
|
||||
QMap<int, QVariantEditorFactoryBase * > factories;
|
||||
QMap<int, QVariantEditorFactoryBase *> factories;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,49 +1,53 @@
|
||||
#include "rangeslider.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QPalette>
|
||||
|
||||
|
||||
RangeSlider::RangeSlider(QWidget * parent)
|
||||
: QWidget(parent),
|
||||
m_minimum(0),
|
||||
m_maximum(100),
|
||||
m_lowerValue(0),
|
||||
m_upperValue(100),
|
||||
mFirstHandlePressed(false),
|
||||
mSecondHandlePressed(false),
|
||||
orientation(Qt::Horizontal),
|
||||
m_mode(DoubleHandles)
|
||||
{init();}
|
||||
: QWidget(parent)
|
||||
, m_minimum(0)
|
||||
, m_maximum(100)
|
||||
, m_lowerValue(0)
|
||||
, m_upperValue(100)
|
||||
, mFirstHandlePressed(false)
|
||||
, mSecondHandlePressed(false)
|
||||
, orientation(Qt::Horizontal)
|
||||
, m_mode(DoubleHandles) {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
RangeSlider::RangeSlider(Qt::Orientation ori, Mode m, QWidget * parent)
|
||||
: QWidget(parent),
|
||||
m_minimum(0),
|
||||
m_maximum(100),
|
||||
m_lowerValue(0),
|
||||
m_upperValue(100),
|
||||
mFirstHandlePressed(false),
|
||||
mSecondHandlePressed(false),
|
||||
orientation(ori),
|
||||
m_mode(m)
|
||||
{init();}
|
||||
: QWidget(parent)
|
||||
, m_minimum(0)
|
||||
, m_maximum(100)
|
||||
, m_lowerValue(0)
|
||||
, m_upperValue(100)
|
||||
, mFirstHandlePressed(false)
|
||||
, mSecondHandlePressed(false)
|
||||
, orientation(ori)
|
||||
, m_mode(m) {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void RangeSlider::init() {
|
||||
setMouseTracking(true);
|
||||
scHandleSideLength = 16*lineThickness(this);
|
||||
scSliderBarHeight = 8*lineThickness(this);
|
||||
scLeftRightMargin = 2*lineThickness(this);
|
||||
scHandleSideLength = 16 * lineThickness(this);
|
||||
scSliderBarHeight = 8 * lineThickness(this);
|
||||
scLeftRightMargin = 2 * lineThickness(this);
|
||||
}
|
||||
|
||||
void RangeSlider::paintEvent(QPaintEvent *) {
|
||||
QPainter painter(this);
|
||||
// Background
|
||||
QRectF backgroundRect;
|
||||
if(orientation == Qt::Horizontal)
|
||||
if (orientation == Qt::Horizontal)
|
||||
backgroundRect = QRectF(scLeftRightMargin, (height() - scSliderBarHeight) / 2, width() - scLeftRightMargin * 2, scSliderBarHeight);
|
||||
else
|
||||
backgroundRect = QRectF((width() - scSliderBarHeight) / 2, scLeftRightMargin, scSliderBarHeight, height() - scLeftRightMargin*2);
|
||||
backgroundRect = QRectF((width() - scSliderBarHeight) / 2, scLeftRightMargin, scSliderBarHeight, height() - scLeftRightMargin * 2);
|
||||
|
||||
QPen pen(palette().color(QPalette::Disabled, QPalette::Text));
|
||||
painter.setPen(pen);
|
||||
@@ -59,18 +63,16 @@ void RangeSlider::paintEvent(QPaintEvent *) {
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBrush(palette().color(QPalette::Active, QPalette::Button));
|
||||
QRectF leftHandleRect = firstHandleRect();
|
||||
if(m_mode.testFlag(LeftHandle))
|
||||
painter.drawEllipse(leftHandleRect);
|
||||
if (m_mode.testFlag(LeftHandle)) painter.drawEllipse(leftHandleRect);
|
||||
|
||||
// Second value handle rect
|
||||
QRectF rightHandleRect = secondHandleRect();
|
||||
if(m_mode.testFlag(RightHandle))
|
||||
painter.drawEllipse(rightHandleRect);
|
||||
if (m_mode.testFlag(RightHandle)) painter.drawEllipse(rightHandleRect);
|
||||
|
||||
// Handles
|
||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
QRectF selectedRect(backgroundRect);
|
||||
if(orientation == Qt::Horizontal) {
|
||||
if (orientation == Qt::Horizontal) {
|
||||
selectedRect.setLeft((m_mode.testFlag(LeftHandle) ? leftHandleRect.right() : leftHandleRect.left()) + 0.5);
|
||||
selectedRect.setRight((m_mode.testFlag(RightHandle) ? rightHandleRect.left() : rightHandleRect.right()) - 0.5);
|
||||
} else {
|
||||
@@ -99,71 +101,73 @@ QRectF RangeSlider::secondHandleRect() const {
|
||||
|
||||
|
||||
QRectF RangeSlider::handleRect(int value) const {
|
||||
if(orientation == Qt::Horizontal)
|
||||
return QRect(value, (height()-scHandleSideLength) / 2, scHandleSideLength, scHandleSideLength);
|
||||
if (orientation == Qt::Horizontal)
|
||||
return QRect(value, (height() - scHandleSideLength) / 2, scHandleSideLength, scHandleSideLength);
|
||||
else
|
||||
return QRect((width()-scHandleSideLength) / 2, value, scHandleSideLength, scHandleSideLength);
|
||||
return QRect((width() - scHandleSideLength) / 2, value, scHandleSideLength, scHandleSideLength);
|
||||
}
|
||||
|
||||
|
||||
void RangeSlider::mousePressEvent(QMouseEvent* e) {
|
||||
if(e->buttons() & Qt::LeftButton) {
|
||||
void RangeSlider::mousePressEvent(QMouseEvent * e) {
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
int posCheck, posMax, posValue, firstHandleRectPosValue, secondHandleRectPosValue;
|
||||
posCheck = (orientation == Qt::Horizontal) ? e->pos().y() : e->pos().x();
|
||||
posMax = (orientation == Qt::Horizontal) ? height() : width();
|
||||
posValue = (orientation == Qt::Horizontal) ? e->pos().x() : e->pos().y();
|
||||
firstHandleRectPosValue = (orientation == Qt::Horizontal) ? firstHandleRect().x() : firstHandleRect().y();
|
||||
posCheck = (orientation == Qt::Horizontal) ? e->pos().y() : e->pos().x();
|
||||
posMax = (orientation == Qt::Horizontal) ? height() : width();
|
||||
posValue = (orientation == Qt::Horizontal) ? e->pos().x() : e->pos().y();
|
||||
firstHandleRectPosValue = (orientation == Qt::Horizontal) ? firstHandleRect().x() : firstHandleRect().y();
|
||||
secondHandleRectPosValue = (orientation == Qt::Horizontal) ? secondHandleRect().x() : secondHandleRect().y();
|
||||
|
||||
mSecondHandlePressed = secondHandleRect().contains(e->pos());
|
||||
mFirstHandlePressed = !mSecondHandlePressed && firstHandleRect().contains(e->pos());
|
||||
if(mFirstHandlePressed) {
|
||||
mSecondHandlePressed = secondHandleRect().contains(e->pos());
|
||||
mFirstHandlePressed = !mSecondHandlePressed && firstHandleRect().contains(e->pos());
|
||||
if (mFirstHandlePressed) {
|
||||
mDelta = posValue - (firstHandleRectPosValue + scHandleSideLength / 2);
|
||||
} else if(mSecondHandlePressed) {
|
||||
} else if (mSecondHandlePressed) {
|
||||
mDelta = posValue - (secondHandleRectPosValue + scHandleSideLength / 2);
|
||||
}
|
||||
if(posCheck >= 2 && posCheck <= posMax - 2) {
|
||||
if (posCheck >= 2 && posCheck <= posMax - 2) {
|
||||
int step = interval() / 10 < 1 ? 1 : interval() / 10;
|
||||
if(posValue < firstHandleRectPosValue)
|
||||
if (posValue < firstHandleRectPosValue)
|
||||
setLowerValue(m_lowerValue - step);
|
||||
else if(((posValue > firstHandleRectPosValue + scHandleSideLength) || !m_mode.testFlag(LeftHandle))
|
||||
&& ((posValue < secondHandleRectPosValue) || !m_mode.testFlag(RightHandle)))
|
||||
{
|
||||
if(m_mode.testFlag(DoubleHandles)) {
|
||||
if(posValue - (firstHandleRectPosValue + scHandleSideLength) <
|
||||
(secondHandleRectPosValue - (firstHandleRectPosValue + scHandleSideLength)) / 2) {
|
||||
else if (((posValue > firstHandleRectPosValue + scHandleSideLength) || !m_mode.testFlag(LeftHandle)) &&
|
||||
((posValue < secondHandleRectPosValue) || !m_mode.testFlag(RightHandle))) {
|
||||
if (m_mode.testFlag(DoubleHandles)) {
|
||||
if (posValue - (firstHandleRectPosValue + scHandleSideLength) <
|
||||
(secondHandleRectPosValue - (firstHandleRectPosValue + scHandleSideLength)) / 2) {
|
||||
setLowerValue((m_lowerValue + step < m_upperValue) ? m_lowerValue + step : m_upperValue);
|
||||
} else {
|
||||
} else {
|
||||
setUpperValue((m_upperValue - step > m_lowerValue) ? m_upperValue - step : m_lowerValue);
|
||||
}
|
||||
} else if(m_mode.testFlag(LeftHandle)) {
|
||||
} else if (m_mode.testFlag(LeftHandle)) {
|
||||
setLowerValue((m_lowerValue + step < m_upperValue) ? m_lowerValue + step : m_upperValue);
|
||||
} else if(m_mode.testFlag(RightHandle)) {
|
||||
} else if (m_mode.testFlag(RightHandle)) {
|
||||
setUpperValue((m_upperValue - step > m_lowerValue) ? m_upperValue - step : m_lowerValue);
|
||||
}
|
||||
}
|
||||
else if(posValue > secondHandleRectPosValue + scHandleSideLength)
|
||||
} else if (posValue > secondHandleRectPosValue + scHandleSideLength)
|
||||
setUpperValue(m_upperValue + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RangeSlider::mouseMoveEvent(QMouseEvent* e) {
|
||||
if(e->buttons() & Qt::LeftButton) {
|
||||
void RangeSlider::mouseMoveEvent(QMouseEvent * e) {
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
int posValue, firstHandleRectPosValue, secondHandleRectPosValue;
|
||||
posValue = (orientation == Qt::Horizontal) ? e->pos().x() : e->pos().y();
|
||||
firstHandleRectPosValue = (orientation == Qt::Horizontal) ? firstHandleRect().x() : firstHandleRect().y();
|
||||
posValue = (orientation == Qt::Horizontal) ? e->pos().x() : e->pos().y();
|
||||
firstHandleRectPosValue = (orientation == Qt::Horizontal) ? firstHandleRect().x() : firstHandleRect().y();
|
||||
secondHandleRectPosValue = (orientation == Qt::Horizontal) ? secondHandleRect().x() : secondHandleRect().y();
|
||||
if(mFirstHandlePressed && m_mode.testFlag(LeftHandle)) {
|
||||
if(posValue - mDelta + scHandleSideLength / 2 <= secondHandleRectPosValue) {
|
||||
setLowerValue((posValue - mDelta - scLeftRightMargin - scHandleSideLength / 2) * 1.0 / validLength() * interval() + m_minimum);
|
||||
if (mFirstHandlePressed && m_mode.testFlag(LeftHandle)) {
|
||||
if (posValue - mDelta + scHandleSideLength / 2 <= secondHandleRectPosValue) {
|
||||
setLowerValue((posValue - mDelta - scLeftRightMargin - scHandleSideLength / 2) * 1.0 / validLength() * interval() +
|
||||
m_minimum);
|
||||
} else {
|
||||
setLowerValue(m_upperValue);
|
||||
}
|
||||
} else if(mSecondHandlePressed && m_mode.testFlag(RightHandle)) {
|
||||
if(firstHandleRectPosValue + scHandleSideLength * (m_mode.testFlag(DoubleHandles) ? 1.5 : 0.5) <= posValue - mDelta) {
|
||||
setUpperValue((posValue - mDelta - scLeftRightMargin - scHandleSideLength / 2 - (m_mode.testFlag(DoubleHandles) ? scHandleSideLength : 0)) * 1.0 / validLength() * interval() + m_minimum);
|
||||
} else if (mSecondHandlePressed && m_mode.testFlag(RightHandle)) {
|
||||
if (firstHandleRectPosValue + scHandleSideLength * (m_mode.testFlag(DoubleHandles) ? 1.5 : 0.5) <= posValue - mDelta) {
|
||||
setUpperValue((posValue - mDelta - scLeftRightMargin - scHandleSideLength / 2 -
|
||||
(m_mode.testFlag(DoubleHandles) ? scHandleSideLength : 0)) *
|
||||
1.0 / validLength() * interval() +
|
||||
m_minimum);
|
||||
} else {
|
||||
setUpperValue(m_lowerValue);
|
||||
}
|
||||
@@ -173,13 +177,13 @@ void RangeSlider::mouseMoveEvent(QMouseEvent* e) {
|
||||
|
||||
|
||||
void RangeSlider::mouseReleaseEvent(QMouseEvent *) {
|
||||
mFirstHandlePressed = false;
|
||||
mFirstHandlePressed = false;
|
||||
mSecondHandlePressed = false;
|
||||
}
|
||||
|
||||
|
||||
void RangeSlider::changeEvent(QEvent * e) {
|
||||
if(e->type() == QEvent::EnabledChange) {
|
||||
if (e->type() == QEvent::EnabledChange) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -191,8 +195,8 @@ QSize RangeSlider::minimumSizeHint() const {
|
||||
|
||||
|
||||
void RangeSlider::setLowerValue(int value) {
|
||||
if(value > m_maximum) value = m_maximum;
|
||||
if(value < m_minimum) value = m_minimum;
|
||||
if (value > m_maximum) value = m_maximum;
|
||||
if (value < m_minimum) value = m_minimum;
|
||||
m_lowerValue = value;
|
||||
emit lowerValueChanged(m_lowerValue);
|
||||
emit valueChanged(m_lowerValue, m_upperValue);
|
||||
@@ -201,8 +205,8 @@ void RangeSlider::setLowerValue(int value) {
|
||||
|
||||
|
||||
void RangeSlider::setUpperValue(int value) {
|
||||
if(value > m_maximum) value = m_maximum;
|
||||
if(value < m_minimum) value = m_minimum;
|
||||
if (value > m_maximum) value = m_maximum;
|
||||
if (value < m_minimum) value = m_minimum;
|
||||
m_upperValue = value;
|
||||
emit upperValueChanged(m_upperValue);
|
||||
emit valueChanged(m_lowerValue, m_upperValue);
|
||||
@@ -211,12 +215,12 @@ void RangeSlider::setUpperValue(int value) {
|
||||
|
||||
|
||||
void RangeSlider::setMinimum(int minimum) {
|
||||
if(minimum <= m_maximum) {
|
||||
if (minimum <= m_maximum) {
|
||||
m_minimum = minimum;
|
||||
} else {
|
||||
int oldMax = m_maximum;
|
||||
m_minimum = oldMax;
|
||||
m_maximum = minimum;
|
||||
m_minimum = oldMax;
|
||||
m_maximum = minimum;
|
||||
}
|
||||
update();
|
||||
setLowerValue(m_minimum);
|
||||
@@ -227,12 +231,12 @@ void RangeSlider::setMinimum(int minimum) {
|
||||
|
||||
|
||||
void RangeSlider::setMaximum(int maximum) {
|
||||
if(maximum >= m_minimum) {
|
||||
if (maximum >= m_minimum) {
|
||||
m_maximum = maximum;
|
||||
} else {
|
||||
int oldMin = m_minimum;
|
||||
m_maximum = oldMin;
|
||||
m_minimum = maximum;
|
||||
m_maximum = oldMin;
|
||||
m_minimum = maximum;
|
||||
}
|
||||
update();
|
||||
setLowerValue(m_minimum);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef RANGESLIDER_H
|
||||
#define RANGESLIDER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QWidget>
|
||||
|
||||
class QAD_WIDGETS_EXPORT RangeSlider : public QWidget
|
||||
{
|
||||
|
||||
class QAD_WIDGETS_EXPORT RangeSlider: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_FLAGS(Mode)
|
||||
Q_PROPERTY(int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
|
||||
@@ -19,29 +19,29 @@ class QAD_WIDGETS_EXPORT RangeSlider : public QWidget
|
||||
|
||||
public:
|
||||
enum ModeEnum {
|
||||
NoHandle = 0x0,
|
||||
LeftHandle = 0x1,
|
||||
RightHandle = 0x2,
|
||||
NoHandle = 0x0,
|
||||
LeftHandle = 0x1,
|
||||
RightHandle = 0x2,
|
||||
DoubleHandles = LeftHandle | RightHandle
|
||||
};
|
||||
Q_DECLARE_FLAGS(Mode, ModeEnum)
|
||||
|
||||
RangeSlider(QWidget* parent = Q_NULLPTR);
|
||||
RangeSlider(QWidget * parent = Q_NULLPTR);
|
||||
RangeSlider(Qt::Orientation ori, Mode m = DoubleHandles, QWidget * parent = Q_NULLPTR);
|
||||
|
||||
|
||||
int minimum() const {return m_minimum;}
|
||||
int maximum() const {return m_maximum;}
|
||||
int lowerValue() const {return m_lowerValue;}
|
||||
int upperValue() const {return m_upperValue;}
|
||||
QPair<int, int> value() const {return QPair<int, int>(m_lowerValue, m_upperValue);}
|
||||
Mode mode() const {return m_mode;}
|
||||
int minimum() const { return m_minimum; }
|
||||
int maximum() const { return m_maximum; }
|
||||
int lowerValue() const { return m_lowerValue; }
|
||||
int upperValue() const { return m_upperValue; }
|
||||
QPair<int, int> value() const { return QPair<int, int>(m_lowerValue, m_upperValue); }
|
||||
Mode mode() const { return m_mode; }
|
||||
|
||||
protected:
|
||||
QSize minimumSizeHint() const override;
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void mousePressEvent(QMouseEvent * e) override;
|
||||
void mouseMoveEvent(QMouseEvent* e) override;
|
||||
void mouseMoveEvent(QMouseEvent * e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *) override;
|
||||
void changeEvent(QEvent * e) override;
|
||||
|
||||
@@ -89,4 +89,4 @@ private:
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(RangeSlider::Mode)
|
||||
|
||||
#endif //RANGESLIDER_H
|
||||
#endif // RANGESLIDER_H
|
||||
|
||||
@@ -13,18 +13,20 @@
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this programap-> If not, see <http://www.gnu.org/licenses/>.
|
||||
along with this programap-> If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "scroll_spin_box.h"
|
||||
|
||||
#include "ui_scroll_spin_box.h"
|
||||
#include <evalspinbox.h>
|
||||
#include <qad_types.h>
|
||||
#include <QStyleOptionSpinBox>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QStyle>
|
||||
#include <QDebug>
|
||||
#include <QStyleOptionSpinBox>
|
||||
#include <evalspinbox.h>
|
||||
#include <qad_types.h>
|
||||
|
||||
|
||||
ScrollSpinBox::ScrollSpinBox(QWidget * parent): QWidget(parent) {
|
||||
@@ -33,10 +35,10 @@ ScrollSpinBox::ScrollSpinBox(QWidget * parent): QWidget(parent) {
|
||||
ui->spin->setPrecision(3);
|
||||
ui->handle->installEventFilter(this);
|
||||
connect(ui->spin, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double)));
|
||||
last_value = 0.;
|
||||
sensivity_ = 0.2;
|
||||
last_value = 0.;
|
||||
sensivity_ = 0.2;
|
||||
scroll_scale = sensivity_ / 10;
|
||||
canceled = false;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +55,8 @@ double ScrollSpinBox::value() const {
|
||||
void ScrollSpinBox::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,15 +72,9 @@ void ScrollSpinBox::resizeEvent(QResizeEvent * e) {
|
||||
|
||||
bool ScrollSpinBox::eventFilter(QObject * o, QEvent * e) {
|
||||
switch (e->type()) {
|
||||
case QEvent::MouseButtonPress:
|
||||
mousePress((QMouseEvent*)e);
|
||||
return true;
|
||||
case QEvent::MouseButtonRelease:
|
||||
mouseRelease((QMouseEvent*)e);
|
||||
return true;
|
||||
case QEvent::MouseMove:
|
||||
mouseMove((QMouseEvent*)e);
|
||||
return true;
|
||||
case QEvent::MouseButtonPress: mousePress((QMouseEvent *)e); return true;
|
||||
case QEvent::MouseButtonRelease: mouseRelease((QMouseEvent *)e); return true;
|
||||
case QEvent::MouseMove: mouseMove((QMouseEvent *)e); return true;
|
||||
default: break;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
@@ -95,8 +88,8 @@ void ScrollSpinBox::mousePress(QMouseEvent * e) {
|
||||
ui->spin->setExpression(last_text);
|
||||
}
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
down_pos = e->pos();
|
||||
last_text = ui->spin->expression();
|
||||
down_pos = e->pos();
|
||||
last_text = ui->spin->expression();
|
||||
last_value = qAbs(ui->spin->value());
|
||||
if (last_value == 0.) last_value = 1.;
|
||||
}
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCROLL_SPIN_BOX_H
|
||||
#define SCROLL_SPIN_BOX_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ScrollSpinBox;
|
||||
class ScrollSpinBox;
|
||||
}
|
||||
|
||||
|
||||
class EvalSpinBox;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ScrollSpinBox: public QWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT ScrollSpinBox: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double sensivity READ sensivity WRITE setSensivity)
|
||||
Q_PROPERTY(double value READ value WRITE setValue)
|
||||
|
||||
public:
|
||||
explicit ScrollSpinBox(QWidget * parent = 0);
|
||||
|
||||
EvalSpinBox * spin();
|
||||
double value() const;
|
||||
double sensivity() const {return sensivity_;}
|
||||
double sensivity() const { return sensivity_; }
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
@@ -59,12 +60,11 @@ protected:
|
||||
bool canceled;
|
||||
|
||||
public slots:
|
||||
void setSensivity(double s) {sensivity_ = s;}
|
||||
void setSensivity(double s) { sensivity_ = s; }
|
||||
void setValue(double v);
|
||||
|
||||
signals:
|
||||
void valueChanged(double);
|
||||
|
||||
};
|
||||
|
||||
#endif // SCROLL_SPIN_BOX_H
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#else
|
||||
# include <QScreen>
|
||||
#endif
|
||||
#include "session_manager.h"
|
||||
#include "qad_locations.h"
|
||||
#include "qad_types.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
|
||||
SessionManager::SessionManager(QString file) {
|
||||
@@ -45,8 +45,8 @@ void SessionManager::removeMainWidget(QWidget * e) {
|
||||
|
||||
|
||||
void SessionManager::addEntry(const QString & name, QMainWindow * e) {
|
||||
mwindows.push_back(QPair<QString, QMainWindow * >(name, e));
|
||||
mw_splitters[e] = e->findChildren<QSplitter * >();
|
||||
mwindows.push_back(QPair<QString, QMainWindow *>(name, e));
|
||||
mw_splitters[e] = e->findChildren<QSplitter *>();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,14 +61,18 @@ void SessionManager::save() {
|
||||
tsc << mwindows[i].second;
|
||||
sr.setValue(mwindows[i].first + " state", mwindows[i].second->saveState(), false);
|
||||
sr.setValue(mwindows[i].first + " window state", (int)mwindows[i].second->windowState(), false);
|
||||
sr.setValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), mwindows[i].second->saveGeometry(), false);
|
||||
QList<QSplitter*> spl = mw_splitters[mwindows[i].second];
|
||||
foreach (QSplitter * s, spl)
|
||||
sr.setValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()),
|
||||
mwindows[i].second->saveGeometry(),
|
||||
false);
|
||||
QList<QSplitter *> spl = mw_splitters[mwindows[i].second];
|
||||
foreach(QSplitter * s, spl)
|
||||
sr.setValue(mwindows[i].first + " splitter " + s->objectName(), s->saveState(), false);
|
||||
}
|
||||
for (int i = 0; i < widgets.size(); ++i) {
|
||||
tsc << widgets[i].second;
|
||||
sr.setValue(widgets[i].first + " geometry " + QString::number((int)widgets[i].second->windowState()), widgets[i].second->saveGeometry(), false);
|
||||
sr.setValue(widgets[i].first + " geometry " + QString::number((int)widgets[i].second->windowState()),
|
||||
widgets[i].second->saveGeometry(),
|
||||
false);
|
||||
sr.setValue(widgets[i].first + " window state", (int)widgets[i].second->windowState(), false);
|
||||
}
|
||||
for (int i = 0; i < checks.size(); ++i)
|
||||
@@ -107,22 +111,22 @@ void SessionManager::save() {
|
||||
sr.setValue(ints[i].first, *ints[i].second, false);
|
||||
for (int i = 0; i < floats.size(); ++i)
|
||||
sr.setValue(floats[i].first, *floats[i].second, false);
|
||||
QSet<QObject*> all_list;
|
||||
foreach (QObject * c, tsc) {
|
||||
all_list |= QList2QSet(c->findChildren<QObject*>());
|
||||
QSet<QObject *> all_list;
|
||||
foreach(QObject * c, tsc) {
|
||||
all_list |= QList2QSet(c->findChildren<QObject *>());
|
||||
}
|
||||
QMap<const QMetaObject*, QByteArray> funcs = metaFunctions(all_list, "sessionSave");
|
||||
//qDebug() << "check for save" << all_list.size();
|
||||
foreach (QObject * o, all_list) {
|
||||
QMap<const QMetaObject *, QByteArray> funcs = metaFunctions(all_list, "sessionSave");
|
||||
// qDebug() << "check for save" << all_list.size();
|
||||
foreach(QObject * o, all_list) {
|
||||
const QMetaObject * mo = o->metaObject();
|
||||
QByteArray fn = funcs.value(mo);
|
||||
QByteArray fn = funcs.value(mo);
|
||||
if (!mo || fn.isEmpty()) continue;
|
||||
QByteArray value;
|
||||
//qDebug() << "save" << o->objectName();
|
||||
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray*, &value));
|
||||
// qDebug() << "save" << o->objectName();
|
||||
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray *, &value));
|
||||
sr.setValue(o->objectName(), value, false);
|
||||
}
|
||||
//qDebug() << mcl.size();
|
||||
// qDebug() << mcl.size();
|
||||
emit saving(sr);
|
||||
sr.writeAll();
|
||||
}
|
||||
@@ -133,7 +137,7 @@ void restoreWindowState(QWidget * w, QPIConfig & sr, QString name) {
|
||||
w->setWindowState(Qt::WindowNoState);
|
||||
w->restoreGeometry(sr.getValue(name + " geometry 0").toByteArray());
|
||||
if (wstate == Qt::WindowMaximized) {
|
||||
QTimer::singleShot(0, w, [w,wstate](){w->setWindowState((Qt::WindowState)wstate);});
|
||||
QTimer::singleShot(0, w, [w, wstate]() { w->setWindowState((Qt::WindowState)wstate); });
|
||||
}
|
||||
bool wnd_ok = false;
|
||||
QRect srect;
|
||||
@@ -143,8 +147,8 @@ void restoreWindowState(QWidget * w, QPIConfig & sr, QString name) {
|
||||
srect = QApplication::desktop()->geometry();
|
||||
}
|
||||
#else
|
||||
QList<QScreen*> sl = QApplication::screens();
|
||||
foreach (QScreen * s, sl) {
|
||||
QList<QScreen *> sl = QApplication::screens();
|
||||
foreach(QScreen * s, sl) {
|
||||
if (s->geometry().contains(w->geometry())) {
|
||||
wnd_ok = true;
|
||||
break;
|
||||
@@ -154,9 +158,10 @@ void restoreWindowState(QWidget * w, QPIConfig & sr, QString name) {
|
||||
#endif
|
||||
if (!wnd_ok) {
|
||||
w->setWindowState(Qt::WindowNoState);
|
||||
w->setGeometry(srect.x() + (srect.width () - w->width ()) / 2,
|
||||
srect.y() + (srect.height() - w->height()) / 2,
|
||||
w->width(), w->height());
|
||||
w->setGeometry(srect.x() + (srect.width() - w->width()) / 2,
|
||||
srect.y() + (srect.height() - w->height()) / 2,
|
||||
w->width(),
|
||||
w->height());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,13 +177,11 @@ void SessionManager::load(bool onlyMainwindow) {
|
||||
QMainWindow * mw = mwindows[i].second;
|
||||
tsc << mw;
|
||||
QByteArray ba = sr.getValue(mwindows[i].first + " state").toByteArray();
|
||||
if (!ba.isEmpty())
|
||||
mw->restoreState(ba);
|
||||
QList<QSplitter*> spl = mw_splitters[mw];
|
||||
foreach (QSplitter * s, spl) {
|
||||
if (!ba.isEmpty()) mw->restoreState(ba);
|
||||
QList<QSplitter *> spl = mw_splitters[mw];
|
||||
foreach(QSplitter * s, spl) {
|
||||
ba = sr.getValue(mwindows[i].first + " splitter " + s->objectName()).toByteArray();
|
||||
if (!ba.isEmpty())
|
||||
s->restoreState(ba);
|
||||
if (!ba.isEmpty()) s->restoreState(ba);
|
||||
}
|
||||
restoreWindowState(mw, sr, mwindows[i].first);
|
||||
}
|
||||
@@ -194,9 +197,8 @@ void SessionManager::load(bool onlyMainwindow) {
|
||||
lines[i].second->setText(sr.getValue(lines[i].first, lines[i].second->text()).toString());
|
||||
for (int i = 0; i < combos.size(); ++i) {
|
||||
QComboBox * c = combos[i].second;
|
||||
int v = sr.getValue(combos[i].first, c->currentIndex()).toInt();
|
||||
if (v >= 0 && v < c->count())
|
||||
c->setCurrentIndex(v);
|
||||
int v = sr.getValue(combos[i].first, c->currentIndex()).toInt();
|
||||
if (v >= 0 && v < c->count()) c->setCurrentIndex(v);
|
||||
}
|
||||
for (int i = 0; i < dspins.size(); ++i)
|
||||
dspins[i].second->setValue(sr.getValue(dspins[i].first, dspins[i].second->value()).toDouble());
|
||||
@@ -208,16 +210,16 @@ void SessionManager::load(bool onlyMainwindow) {
|
||||
evals[i].second->setExpression(sr.getValue(evals[i].first, evals[i].second->expression()).toString());
|
||||
for (int i = 0; i < tabs.size(); ++i) {
|
||||
QTabWidget * t = tabs[i].second;
|
||||
int v = sr.getValue(tabs[i].first, t->currentIndex()).toDouble();
|
||||
if (v >= 0 && v < t->count())
|
||||
t->setCurrentIndex(v);
|
||||
int v = sr.getValue(tabs[i].first, t->currentIndex()).toDouble();
|
||||
if (v >= 0 && v < t->count()) t->setCurrentIndex(v);
|
||||
}
|
||||
for (int i = 0; i < groups.size(); ++i)
|
||||
groups[i].second->setChecked(sr.getValue(groups[i].first, groups[i].second->isChecked()).toBool());
|
||||
for (int i = 0; i < buttons.size(); ++i)
|
||||
buttons[i].second->setChecked(sr.getValue(buttons[i].first, buttons[i].second->isChecked()).toBool());
|
||||
for (int i = 0; i < stacks.size(); ++i)
|
||||
stacks[i].second->setCurrentIndex(qMin<int>(sr.getValue(stacks[i].first, stacks[i].second->currentIndex()).toInt(), stacks[i].second->count()));
|
||||
stacks[i].second->setCurrentIndex(
|
||||
qMin<int>(sr.getValue(stacks[i].first, stacks[i].second->currentIndex()).toInt(), stacks[i].second->count()));
|
||||
for (int i = 0; i < actions.size(); ++i)
|
||||
actions[i].second->setChecked(sr.getValue(actions[i].first, actions[i].second->isChecked()).toBool());
|
||||
for (int i = 0; i < stringlists.size(); ++i)
|
||||
@@ -232,19 +234,19 @@ void SessionManager::load(bool onlyMainwindow) {
|
||||
*ints[i].second = sr.getValue(ints[i].first, *ints[i].second).toInt();
|
||||
for (int i = 0; i < floats.size(); ++i)
|
||||
*floats[i].second = sr.getValue(floats[i].first, *floats[i].second).toFloat();
|
||||
QSet<QObject*> all_list;
|
||||
foreach (QObject * c, tsc) {
|
||||
all_list |= QList2QSet(c->findChildren<QObject*>());
|
||||
QSet<QObject *> all_list;
|
||||
foreach(QObject * c, tsc) {
|
||||
all_list |= QList2QSet(c->findChildren<QObject *>());
|
||||
}
|
||||
QMap<const QMetaObject*, QByteArray> funcs = metaFunctions(all_list, "sessionLoad");
|
||||
//qDebug() << "check for load" << all_list.size();
|
||||
foreach (QObject * o, all_list) {
|
||||
QMap<const QMetaObject *, QByteArray> funcs = metaFunctions(all_list, "sessionLoad");
|
||||
// qDebug() << "check for load" << all_list.size();
|
||||
foreach(QObject * o, all_list) {
|
||||
const QMetaObject * mo = o->metaObject();
|
||||
QByteArray fn = funcs.value(mo);
|
||||
QByteArray fn = funcs.value(mo);
|
||||
if (!mo || fn.isEmpty()) continue;
|
||||
QByteArray value = sr.getValue(o->objectName()).toByteArray();
|
||||
//qDebug() << "load" << o->objectName();
|
||||
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray*, &value));
|
||||
// qDebug() << "load" << o->objectName();
|
||||
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray *, &value));
|
||||
}
|
||||
emit loading(sr);
|
||||
}
|
||||
@@ -276,8 +278,8 @@ void SessionManager::clear(bool with_filename) {
|
||||
|
||||
|
||||
QMap<const QMetaObject *, QByteArray> SessionManager::metaFunctions(const QSet<QObject *> & objects, QByteArray fname) {
|
||||
QMap<const QMetaObject*, QByteArray> funcs;
|
||||
foreach (QObject * o, objects) {
|
||||
QMap<const QMetaObject *, QByteArray> funcs;
|
||||
foreach(QObject * o, objects) {
|
||||
const QMetaObject * mo = o->metaObject();
|
||||
if (!mo) continue;
|
||||
QByteArray fn;
|
||||
@@ -286,9 +288,9 @@ QMap<const QMetaObject *, QByteArray> SessionManager::metaFunctions(const QSet<Q
|
||||
QMetaMethod mm = mo->method(i);
|
||||
QByteArray mmn =
|
||||
#if QT_VERSION >= 0x050000
|
||||
mm.name();
|
||||
mm.name();
|
||||
#else
|
||||
mm.signature();
|
||||
mm.signature();
|
||||
mmn = mmn.left(mmn.indexOf('('));
|
||||
#endif
|
||||
|
||||
@@ -301,7 +303,8 @@ QMap<const QMetaObject *, QByteArray> SessionManager::metaFunctions(const QSet<Q
|
||||
}
|
||||
}
|
||||
funcs[mo] = fn;
|
||||
} else fn = funcs[mo];
|
||||
} else
|
||||
fn = funcs[mo];
|
||||
}
|
||||
return funcs;
|
||||
}
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SESSION_MANAGER_H
|
||||
#define SESSION_MANAGER_H
|
||||
|
||||
#include <QPair>
|
||||
#include <QMainWindow>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QDoubleSpinBox>
|
||||
#include "evalspinbox.h"
|
||||
#include "qad_widgets_export.h"
|
||||
#include "qpiconfig.h"
|
||||
#include "spinslider.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QPair>
|
||||
#include <QSplitter>
|
||||
#include <QStackedWidget>
|
||||
#include <QGroupBox>
|
||||
#include "spinslider.h"
|
||||
#include "evalspinbox.h"
|
||||
#include "qpiconfig.h"
|
||||
#include "qad_widgets_export.h"
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
|
||||
|
||||
/// for all children widgets of "QMainWindow"s and MainWidgets
|
||||
@@ -44,88 +45,87 @@
|
||||
/// * void sessionLoad(QByteArray * data);
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT SessionManager: public QObject
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT SessionManager: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SessionManager(QString file = QString());
|
||||
|
||||
void setFile(const QString & file);
|
||||
|
||||
void addEntry(QMainWindow * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QCheckBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QLineEdit * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QComboBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QDoubleSpinBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QSpinBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(SpinSlider * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(EvalSpinBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QTabWidget * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QGroupBox * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QAction * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QAbstractButton * e) {addEntry(e->objectName(), e);}
|
||||
void addEntry(QStackedWidget * e) {addEntry(e->objectName(), e);}
|
||||
void addMainWidget(QWidget * e) {addMainWidget(e->objectName(), e);}
|
||||
void addEntry(QMainWindow * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QCheckBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QLineEdit * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QComboBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QDoubleSpinBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QSpinBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(SpinSlider * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(EvalSpinBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QTabWidget * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QGroupBox * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QAction * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QAbstractButton * e) { addEntry(e->objectName(), e); }
|
||||
void addEntry(QStackedWidget * e) { addEntry(e->objectName(), e); }
|
||||
void addMainWidget(QWidget * e) { addMainWidget(e->objectName(), e); }
|
||||
void removeMainWidget(QWidget * e);
|
||||
|
||||
void addEntry(const QString & name, QMainWindow * e);
|
||||
void addEntry(const QString & name, QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(name, e));}
|
||||
void addEntry(const QString & name, QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(name, e));}
|
||||
void addEntry(const QString & name, QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(name, e));}
|
||||
void addEntry(const QString & name, QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(name, e));}
|
||||
void addEntry(const QString & name, QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(name, e));}
|
||||
void addEntry(const QString & name, SpinSlider * e) {spinsliders.push_back(QPair<QString, SpinSlider * >(name, e));}
|
||||
void addEntry(const QString & name, EvalSpinBox * e) {evals.push_back(QPair<QString, EvalSpinBox * >(name, e));}
|
||||
void addEntry(const QString & name, QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(name, e));}
|
||||
void addEntry(const QString & name, QGroupBox * e) {groups.push_back(QPair<QString, QGroupBox * >(name, e));}
|
||||
void addEntry(const QString & name, QAbstractButton * e) {buttons.push_back(QPair<QString, QAbstractButton * >(name, e));}
|
||||
void addEntry(const QString & name, QStackedWidget * e) {stacks.push_back(QPair<QString, QStackedWidget * >(name, e));}
|
||||
void addEntry(const QString & name, QAction * e) {actions.push_back(QPair<QString, QAction * >(name, e));}
|
||||
void addEntry(const QString & name, QStringList * e) {stringlists.push_back(QPair<QString, QStringList * >(name, e));}
|
||||
void addEntry(const QString & name, QString * e) {strings.push_back(QPair<QString, QString * >(name, e));}
|
||||
void addEntry(const QString & name, QColor * e) {colors.push_back(QPair<QString, QColor * >(name, e));}
|
||||
void addEntry(const QString & name, bool * e) {bools.push_back(QPair<QString, bool * >(name, e));}
|
||||
void addEntry(const QString & name, int * e) {ints.push_back(QPair<QString, int * >(name, e));}
|
||||
void addEntry(const QString & name, float * e) {floats.push_back(QPair<QString, float * >(name, e));}
|
||||
void addMainWidget(const QString & name, QWidget * e) {widgets.push_back(QPair<QString, QWidget * >(name, e));}
|
||||
void addEntry(const QString & name, QMainWindow * e);
|
||||
void addEntry(const QString & name, QCheckBox * e) { checks.push_back(QPair<QString, QCheckBox *>(name, e)); }
|
||||
void addEntry(const QString & name, QLineEdit * e) { lines.push_back(QPair<QString, QLineEdit *>(name, e)); }
|
||||
void addEntry(const QString & name, QComboBox * e) { combos.push_back(QPair<QString, QComboBox *>(name, e)); }
|
||||
void addEntry(const QString & name, QDoubleSpinBox * e) { dspins.push_back(QPair<QString, QDoubleSpinBox *>(name, e)); }
|
||||
void addEntry(const QString & name, QSpinBox * e) { spins.push_back(QPair<QString, QSpinBox *>(name, e)); }
|
||||
void addEntry(const QString & name, SpinSlider * e) { spinsliders.push_back(QPair<QString, SpinSlider *>(name, e)); }
|
||||
void addEntry(const QString & name, EvalSpinBox * e) { evals.push_back(QPair<QString, EvalSpinBox *>(name, e)); }
|
||||
void addEntry(const QString & name, QTabWidget * e) { tabs.push_back(QPair<QString, QTabWidget *>(name, e)); }
|
||||
void addEntry(const QString & name, QGroupBox * e) { groups.push_back(QPair<QString, QGroupBox *>(name, e)); }
|
||||
void addEntry(const QString & name, QAbstractButton * e) { buttons.push_back(QPair<QString, QAbstractButton *>(name, e)); }
|
||||
void addEntry(const QString & name, QStackedWidget * e) { stacks.push_back(QPair<QString, QStackedWidget *>(name, e)); }
|
||||
void addEntry(const QString & name, QAction * e) { actions.push_back(QPair<QString, QAction *>(name, e)); }
|
||||
void addEntry(const QString & name, QStringList * e) { stringlists.push_back(QPair<QString, QStringList *>(name, e)); }
|
||||
void addEntry(const QString & name, QString * e) { strings.push_back(QPair<QString, QString *>(name, e)); }
|
||||
void addEntry(const QString & name, QColor * e) { colors.push_back(QPair<QString, QColor *>(name, e)); }
|
||||
void addEntry(const QString & name, bool * e) { bools.push_back(QPair<QString, bool *>(name, e)); }
|
||||
void addEntry(const QString & name, int * e) { ints.push_back(QPair<QString, int *>(name, e)); }
|
||||
void addEntry(const QString & name, float * e) { floats.push_back(QPair<QString, float *>(name, e)); }
|
||||
void addMainWidget(const QString & name, QWidget * e) { widgets.push_back(QPair<QString, QWidget *>(name, e)); }
|
||||
|
||||
private:
|
||||
QMap<const QMetaObject*, QByteArray> metaFunctions(const QSet<QObject*> & objects, QByteArray fname);
|
||||
QMap<const QMetaObject *, QByteArray> metaFunctions(const QSet<QObject *> & objects, QByteArray fname);
|
||||
|
||||
QVector<QPair<QString, QMainWindow * > > mwindows;
|
||||
QVector<QPair<QString, QWidget * > > widgets;
|
||||
QVector<QPair<QString, QCheckBox * > > checks;
|
||||
QVector<QPair<QString, QLineEdit * > > lines;
|
||||
QVector<QPair<QString, QComboBox * > > combos;
|
||||
QVector<QPair<QString, QDoubleSpinBox * > > dspins;
|
||||
QVector<QPair<QString, QSpinBox * > > spins;
|
||||
QVector<QPair<QString, SpinSlider * > > spinsliders;
|
||||
QVector<QPair<QString, EvalSpinBox * > > evals;
|
||||
QVector<QPair<QString, QTabWidget * > > tabs;
|
||||
QVector<QPair<QString, QGroupBox * > > groups;
|
||||
QVector<QPair<QString, QAbstractButton * > > buttons;
|
||||
QVector<QPair<QString, QStackedWidget * > > stacks;
|
||||
QVector<QPair<QString, QAction * > > actions;
|
||||
QVector<QPair<QString, QStringList * > > stringlists;
|
||||
QVector<QPair<QString, QString * > > strings;
|
||||
QVector<QPair<QString, QColor * > > colors;
|
||||
QVector<QPair<QString, bool * > > bools;
|
||||
QVector<QPair<QString, int * > > ints;
|
||||
QVector<QPair<QString, float * > > floats;
|
||||
QMap<QMainWindow*, QList<QSplitter*> > mw_splitters;
|
||||
QVector<QPair<QString, QMainWindow *>> mwindows;
|
||||
QVector<QPair<QString, QWidget *>> widgets;
|
||||
QVector<QPair<QString, QCheckBox *>> checks;
|
||||
QVector<QPair<QString, QLineEdit *>> lines;
|
||||
QVector<QPair<QString, QComboBox *>> combos;
|
||||
QVector<QPair<QString, QDoubleSpinBox *>> dspins;
|
||||
QVector<QPair<QString, QSpinBox *>> spins;
|
||||
QVector<QPair<QString, SpinSlider *>> spinsliders;
|
||||
QVector<QPair<QString, EvalSpinBox *>> evals;
|
||||
QVector<QPair<QString, QTabWidget *>> tabs;
|
||||
QVector<QPair<QString, QGroupBox *>> groups;
|
||||
QVector<QPair<QString, QAbstractButton *>> buttons;
|
||||
QVector<QPair<QString, QStackedWidget *>> stacks;
|
||||
QVector<QPair<QString, QAction *>> actions;
|
||||
QVector<QPair<QString, QStringList *>> stringlists;
|
||||
QVector<QPair<QString, QString *>> strings;
|
||||
QVector<QPair<QString, QColor *>> colors;
|
||||
QVector<QPair<QString, bool *>> bools;
|
||||
QVector<QPair<QString, int *>> ints;
|
||||
QVector<QPair<QString, float *>> floats;
|
||||
QMap<QMainWindow *, QList<QSplitter *>> mw_splitters;
|
||||
QString file_;
|
||||
|
||||
public slots:
|
||||
void save();
|
||||
void load(bool onlyMainwindow);
|
||||
void load() {load(false);}
|
||||
void load() { load(false); }
|
||||
void clear(bool with_filename);
|
||||
void clear() {clear(true);}
|
||||
void clear() { clear(true); }
|
||||
|
||||
signals:
|
||||
void loading(QPIConfig & );
|
||||
void saving(QPIConfig & );
|
||||
|
||||
void loading(QPIConfig &);
|
||||
void saving(QPIConfig &);
|
||||
};
|
||||
|
||||
#endif // SESSION_MANAGER_H
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
#include "shortcuts.h"
|
||||
#include <QPainter>
|
||||
|
||||
#include <QAction>
|
||||
#include <QKeyEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
#include <QShortcut>
|
||||
#include <QWidgetAction>
|
||||
#include <QMainWindow>
|
||||
#include <QToolBar>
|
||||
#include <QWidgetAction>
|
||||
|
||||
|
||||
/// ShortcutEdit
|
||||
|
||||
ShortcutEdit::ShortcutEdit(QWidget *parent) : CLineEdit(parent) {
|
||||
ShortcutEdit::ShortcutEdit(QWidget * parent): CLineEdit(parent) {
|
||||
ti = nullptr;
|
||||
ca = nullptr;
|
||||
connect(this, &CLineEdit::textChanged, this, &ShortcutEdit::textChangedSlot);
|
||||
@@ -24,21 +25,20 @@ void ShortcutEdit::keyPressEvent(QKeyEvent * e) {
|
||||
Qt::KeyboardModifiers km = e->modifiers();
|
||||
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());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShortcutEdit::assignAction(QAction *a) {
|
||||
void ShortcutEdit::assignAction(QAction * a) {
|
||||
clear();
|
||||
ca = a;
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
QAction *ShortcutEdit::action() const {
|
||||
QAction * ShortcutEdit::action() const {
|
||||
return ca;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) {
|
||||
p.eraseRect(ti.rect());
|
||||
p.end();
|
||||
empty_icon = QPixmap::fromImage(ti);
|
||||
bfont = font();
|
||||
bfont = font();
|
||||
bfont.setWeight(QFont::Bold);
|
||||
active = on;
|
||||
setColumnCount(2);
|
||||
@@ -103,7 +103,7 @@ Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) {
|
||||
|
||||
|
||||
Shortcuts::~Shortcuts() {
|
||||
for (ShortcutEdit * i : edits) {
|
||||
for (ShortcutEdit * i: edits) {
|
||||
delete i;
|
||||
}
|
||||
edits.clear();
|
||||
@@ -125,28 +125,28 @@ void Shortcuts::assignWindow(QWidget * w) {
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
while (!(qobject_cast<QMainWindow * >(w)) && (w->parentWidget())) {
|
||||
while (!(qobject_cast<QMainWindow *>(w)) && (w->parentWidget())) {
|
||||
w = w->parentWidget();
|
||||
}
|
||||
aw = qobject_cast<QMainWindow * >(w);
|
||||
aw = qobject_cast<QMainWindow *>(w);
|
||||
updateShortcuts();
|
||||
}
|
||||
|
||||
|
||||
QStringList Shortcuts::actionTree(QAction * a) {
|
||||
QStringList tree;
|
||||
QList<QWidget * > aw = a->associatedWidgets();
|
||||
QList<QWidget *> aw = a->associatedWidgets();
|
||||
if (aw.size() == 0) {
|
||||
return tree;
|
||||
}
|
||||
for (QWidget * i : aw) {
|
||||
auto tm = qobject_cast<QMenu * >(i);
|
||||
for (QWidget * i: aw) {
|
||||
auto tm = qobject_cast<QMenu *>(i);
|
||||
if (!tm) {
|
||||
continue;
|
||||
}
|
||||
auto cw = i;
|
||||
while (cw) {
|
||||
tm = qobject_cast<QMenu * >(cw);
|
||||
tm = qobject_cast<QMenu *>(cw);
|
||||
if (tm) {
|
||||
if (!tm->title().isEmpty()) {
|
||||
tree.push_front(tm->title());
|
||||
@@ -160,8 +160,8 @@ QStringList Shortcuts::actionTree(QAction * a) {
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
for (QWidget * i : aw) {
|
||||
auto tt = qobject_cast<QToolBar * >(i);
|
||||
for (QWidget * i: aw) {
|
||||
auto tt = qobject_cast<QToolBar *>(i);
|
||||
if (!tt) {
|
||||
continue;
|
||||
}
|
||||
@@ -174,9 +174,9 @@ QStringList Shortcuts::actionTree(QAction * a) {
|
||||
}
|
||||
|
||||
|
||||
QList<QPair<QString, QKeySequence> > Shortcuts::shortcuts() {
|
||||
QList<QPair<QString, QKeySequence> > l;
|
||||
for (const ShortcutEdit * i : edits) {
|
||||
QList<QPair<QString, QKeySequence>> Shortcuts::shortcuts() {
|
||||
QList<QPair<QString, QKeySequence>> l;
|
||||
for (const ShortcutEdit * i: edits) {
|
||||
if (i->action()->objectName().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -187,12 +187,12 @@ QList<QPair<QString, QKeySequence> > Shortcuts::shortcuts() {
|
||||
|
||||
|
||||
void Shortcuts::clear() {
|
||||
foreach (ShortcutEdit * i, edits)
|
||||
foreach(ShortcutEdit * i, edits)
|
||||
delete i;
|
||||
edits.clear();
|
||||
hide();
|
||||
QList<QTreeWidgetItem * > tl = findItems("", Qt::MatchContains);
|
||||
foreach (QTreeWidgetItem * i, tl)
|
||||
QList<QTreeWidgetItem *> tl = findItems("", Qt::MatchContains);
|
||||
foreach(QTreeWidgetItem * i, tl)
|
||||
delete i;
|
||||
show();
|
||||
}
|
||||
@@ -208,7 +208,7 @@ bool Shortcuts::checkAction(QAction * a) {
|
||||
if (QString(a->metaObject()->className()) != "QAction") {
|
||||
return false;
|
||||
}
|
||||
if (qobject_cast<QWidgetAction * >(a)) {
|
||||
if (qobject_cast<QWidgetAction *>(a)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -227,21 +227,21 @@ void Shortcuts::updateShortcuts() {
|
||||
#else
|
||||
header()->setSectionResizeMode(0, QHeaderView::Fixed);
|
||||
#endif
|
||||
QList<QAction * > al = aw->findChildren<QAction * >();
|
||||
QTreeWidgetItem * pi, * ci;
|
||||
QList<QAction *> al = aw->findChildren<QAction *>();
|
||||
QTreeWidgetItem *pi, *ci;
|
||||
QStringList tree;
|
||||
bool s = isSortingEnabled(), isFound;
|
||||
setSortingEnabled(false);
|
||||
for (QAction * i : al) {
|
||||
for (QAction * i: al) {
|
||||
if (!checkAction(i)) continue;
|
||||
edits.push_back(new ShortcutEdit());
|
||||
tree = actionTree(i);
|
||||
pi = invisibleRootItem();
|
||||
for (const QString & t : tree) {
|
||||
pi = invisibleRootItem();
|
||||
for (const QString & t: tree) {
|
||||
isFound = false;
|
||||
for (int j = 0; j < pi->childCount(); ++j) {
|
||||
if (pi->child(j)->text(0) == t) {
|
||||
pi = pi->child(j);
|
||||
pi = pi->child(j);
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ void Shortcuts::updateShortcuts() {
|
||||
edits.back()->ti = ci;
|
||||
edits.back()->assignAction(i);
|
||||
pi->addChild(ci);
|
||||
//qDebug() << "set widget" << edits.back();
|
||||
// qDebug() << "set widget" << edits.back();
|
||||
setItemWidget(ci, 1, edits.back());
|
||||
}
|
||||
setSortingEnabled(s);
|
||||
@@ -280,14 +280,14 @@ void Shortcuts::updateShortcuts() {
|
||||
|
||||
|
||||
void Shortcuts::commit() {
|
||||
for (ShortcutEdit * i : edits) {
|
||||
for (ShortcutEdit * i: edits) {
|
||||
i->commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Shortcuts::resetShortcuts() {
|
||||
for (ShortcutEdit * i : edits) {
|
||||
for (ShortcutEdit * i: edits) {
|
||||
i->reset();
|
||||
}
|
||||
updateShortcuts();
|
||||
@@ -317,9 +317,8 @@ bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) {
|
||||
isFound = true;
|
||||
}
|
||||
}
|
||||
if (ti->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0 ||
|
||||
ti->text(1).indexOf(f, 0, Qt::CaseInsensitive) >= 0) {
|
||||
isFound = true;
|
||||
if (ti->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0 || ti->text(1).indexOf(f, 0, Qt::CaseInsensitive) >= 0) {
|
||||
isFound = true;
|
||||
}
|
||||
ti->setHidden(!isFound);
|
||||
return isFound;
|
||||
@@ -327,8 +326,7 @@ bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) {
|
||||
|
||||
|
||||
void Shortcuts::updateEditorGeometries() {
|
||||
for (ShortcutEdit * i : edits) {
|
||||
for (ShortcutEdit * i: edits) {
|
||||
i->setGeometry(visualRect(indexFromItem(i->ti, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SHORTCUTS_H
|
||||
#define SHORTCUTS_H
|
||||
|
||||
#include "qad_widgets_export.h"
|
||||
#include "clineedit.h"
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
|
||||
@@ -29,15 +30,15 @@ class QMainWindow;
|
||||
class ShortcutEdit;
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT ShortcutEdit: public CLineEdit {
|
||||
Q_OBJECT
|
||||
friend class Shortcuts;
|
||||
public:
|
||||
explicit ShortcutEdit(QWidget *parent = nullptr);
|
||||
|
||||
void assignAction(QAction *a);
|
||||
QAction *action() const;
|
||||
public:
|
||||
explicit ShortcutEdit(QWidget * parent = nullptr);
|
||||
|
||||
void assignAction(QAction * a);
|
||||
QAction * action() const;
|
||||
bool isEmpty() const;
|
||||
void commit();
|
||||
void reset();
|
||||
@@ -53,18 +54,18 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class QAD_WIDGETS_EXPORT Shortcuts: public QTreeWidget
|
||||
{
|
||||
class QAD_WIDGETS_EXPORT Shortcuts: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Shortcuts(QWidget * parent = nullptr, bool on = true);
|
||||
~Shortcuts() override;
|
||||
|
||||
void assignWindow(QWidget * w);
|
||||
void setActive(bool on) {active = on;}
|
||||
void setActive(bool on) { active = on; }
|
||||
QStringList actionTree(QAction * a);
|
||||
static bool checkAction(QAction * a);
|
||||
QList<QPair<QString, QKeySequence> > shortcuts();
|
||||
QList<QPair<QString, QKeySequence>> shortcuts();
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
@@ -76,7 +77,7 @@ public slots:
|
||||
private:
|
||||
virtual void updateEditorGeometries() override;
|
||||
virtual void changeEvent(QEvent *) override;
|
||||
bool filterTree(QTreeWidgetItem *ti, QString f);
|
||||
bool filterTree(QTreeWidgetItem * ti, QString f);
|
||||
|
||||
QMainWindow * aw;
|
||||
QVector<ShortcutEdit *> edits;
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#include "spinslider.h"
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
|
||||
SpinSlider::SpinSlider(QWidget * parent): QWidget(parent) {
|
||||
min_ = val_ = 0.;
|
||||
max_ = 100.;
|
||||
dec_ = 1;
|
||||
page = 10.;
|
||||
ticks_ = 1;
|
||||
direc = LeftToRight;
|
||||
square = false;
|
||||
slider = new QSlider();
|
||||
max_ = 100.;
|
||||
dec_ = 1;
|
||||
page = 10.;
|
||||
ticks_ = 1;
|
||||
direc = LeftToRight;
|
||||
square = false;
|
||||
slider = new QSlider();
|
||||
slider->setOrientation(Qt::Horizontal);
|
||||
slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
spin = new QDoubleSpinBox();
|
||||
@@ -51,23 +52,29 @@ bool SpinSlider::adaptiveStep() const {
|
||||
|
||||
void SpinSlider::setAdaptiveStep(bool on) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
if (on) spin->setStepType(QDoubleSpinBox::AdaptiveDecimalStepType);
|
||||
else spin->setStepType(QDoubleSpinBox::DefaultStepType);
|
||||
if (on)
|
||||
spin->setStepType(QDoubleSpinBox::AdaptiveDecimalStepType);
|
||||
else
|
||||
spin->setStepType(QDoubleSpinBox::DefaultStepType);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SpinSlider::adjust() {
|
||||
adjusting = true;
|
||||
delim = qPow(10, dec_);
|
||||
delim = qPow(10, dec_);
|
||||
spin->setDecimals(dec_);
|
||||
spin->setRange(min_, max_);
|
||||
if (square) slider->setRange(sqrt(min_ * delim), sqrt(max_ * delim));
|
||||
else slider->setRange(min_ * delim, max_ * delim);
|
||||
if (square)
|
||||
slider->setRange(sqrt(min_ * delim), sqrt(max_ * delim));
|
||||
else
|
||||
slider->setRange(min_ * delim, max_ * delim);
|
||||
if (val_ < min_) val_ = min_;
|
||||
if (val_ > max_) val_ = max_;
|
||||
spin->setValue(val_);
|
||||
if (square) slider->setValue(static_cast<int>(sqrt(val_ * delim)));
|
||||
else slider->setValue(static_cast<int>(val_ * delim));
|
||||
if (square)
|
||||
slider->setValue(static_cast<int>(sqrt(val_ * delim)));
|
||||
else
|
||||
slider->setValue(static_cast<int>(val_ * delim));
|
||||
slider->setPageStep(qRound(page * delim));
|
||||
slider->setTickInterval(qRound(ticks_ * delim));
|
||||
emit valueChanged(val_);
|
||||
@@ -79,8 +86,10 @@ void SpinSlider::adjust() {
|
||||
void SpinSlider::sliderChanged(int value) {
|
||||
if (adjusting) return;
|
||||
adjusting = true;
|
||||
if (square) spin->setValue(static_cast<double>(sqr(value) / delim));
|
||||
else spin->setValue(static_cast<double>(value) / delim);
|
||||
if (square)
|
||||
spin->setValue(static_cast<double>(sqr(value) / delim));
|
||||
else
|
||||
spin->setValue(static_cast<double>(value) / delim);
|
||||
val_ = spin->value();
|
||||
emit valueChanged(val_);
|
||||
emit valueChangedInt(qRound(val_));
|
||||
@@ -91,9 +100,11 @@ void SpinSlider::sliderChanged(int value) {
|
||||
void SpinSlider::spinChanged(double value) {
|
||||
if (adjusting) return;
|
||||
adjusting = true;
|
||||
val_ = value;
|
||||
if (square) slider->setValue(static_cast<int>(sqrt(value * delim)));
|
||||
else slider->setValue(qRound(value * delim));
|
||||
val_ = value;
|
||||
if (square)
|
||||
slider->setValue(static_cast<int>(sqrt(value * delim)));
|
||||
else
|
||||
slider->setValue(qRound(value * delim));
|
||||
emit valueChanged(val_);
|
||||
emit valueChangedInt(qRound(val_));
|
||||
adjusting = false;
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SPINSLIDER_H
|
||||
#define SPINSLIDER_H
|
||||
|
||||
#include <QSlider>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QBoxLayout>
|
||||
#include "qad_widgets_export.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSlider>
|
||||
|
||||
class QAD_WIDGETS_EXPORT SpinSlider: public QWidget
|
||||
{
|
||||
|
||||
class QAD_WIDGETS_EXPORT SpinSlider: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Direction)
|
||||
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
|
||||
@@ -52,50 +52,85 @@ public:
|
||||
explicit SpinSlider(QWidget * parent = 0);
|
||||
~SpinSlider();
|
||||
|
||||
enum Direction {LeftToRight, RightToLeft, TopToBottom, BottomToTop};
|
||||
enum Direction {
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
TopToBottom,
|
||||
BottomToTop
|
||||
};
|
||||
|
||||
double minimum() const {return min_;}
|
||||
double maximum() const {return max_;}
|
||||
double spinMinimum() const {return spin->minimum();}
|
||||
double spinMaximum() const {return spin->maximum();}
|
||||
double value() const {return val_;}
|
||||
int decimals() const {return dec_;}
|
||||
double singleStep() const {return spin->singleStep();}
|
||||
double minimum() const { return min_; }
|
||||
double maximum() const { return max_; }
|
||||
double spinMinimum() const { return spin->minimum(); }
|
||||
double spinMaximum() const { return spin->maximum(); }
|
||||
double value() const { return val_; }
|
||||
int decimals() const { return dec_; }
|
||||
double singleStep() const { return spin->singleStep(); }
|
||||
bool adaptiveStep() const;
|
||||
double pageStep() const {return page;}
|
||||
QString prefix() const {return spin->prefix();}
|
||||
QString suffix() const {return spin->suffix();}
|
||||
QSlider::TickPosition tickPosition() const {return slider->tickPosition();}
|
||||
int tickInterval() const {return ticks_;}
|
||||
Qt::Orientation orientation() const {return slider->orientation();}
|
||||
Direction direction() const {return direc;}
|
||||
bool invertedAppearance() const {return slider->invertedAppearance();}
|
||||
bool squareScale() const {return square;}
|
||||
double pageStep() const { return page; }
|
||||
QString prefix() const { return spin->prefix(); }
|
||||
QString suffix() const { return spin->suffix(); }
|
||||
QSlider::TickPosition tickPosition() const { return slider->tickPosition(); }
|
||||
int tickInterval() const { return ticks_; }
|
||||
Qt::Orientation orientation() const { return slider->orientation(); }
|
||||
Direction direction() const { return direc; }
|
||||
bool invertedAppearance() const { return slider->invertedAppearance(); }
|
||||
bool squareScale() const { return square; }
|
||||
|
||||
void setSingleStep(double step) {spin->setSingleStep(step); slider->setPageStep(qRound(step * delim));}
|
||||
void setSingleStep(double step) {
|
||||
spin->setSingleStep(step);
|
||||
slider->setPageStep(qRound(step * delim));
|
||||
}
|
||||
void setAdaptiveStep(bool on);
|
||||
void setPageStep(double step) {page = step; slider->setPageStep(qRound(page * delim));}
|
||||
void setPrefix(QString prefix) {spin->setPrefix(prefix);}
|
||||
void setSuffix(QString suffix) {spin->setSuffix(suffix);}
|
||||
void setTickPosition(QSlider::TickPosition tp) {slider->setTickPosition(tp);}
|
||||
void setTickInterval(int ti) {ticks_ = ti; slider->setTickInterval(qRound(ticks_ * delim));}
|
||||
void setPageStep(double step) {
|
||||
page = step;
|
||||
slider->setPageStep(qRound(page * delim));
|
||||
}
|
||||
void setPrefix(QString prefix) { spin->setPrefix(prefix); }
|
||||
void setSuffix(QString suffix) { spin->setSuffix(suffix); }
|
||||
void setTickPosition(QSlider::TickPosition tp) { slider->setTickPosition(tp); }
|
||||
void setTickInterval(int ti) {
|
||||
ticks_ = ti;
|
||||
slider->setTickInterval(qRound(ticks_ * delim));
|
||||
}
|
||||
void setOrientation(Qt::Orientation orient);
|
||||
void setDirection(Direction d) {direc = d; layout->setDirection((QBoxLayout::Direction)d);}
|
||||
void setInvertedAppearance(bool yes) {slider->setInvertedAppearance(yes);}
|
||||
void setSquareScale(bool yes) {square = yes; adjust();}
|
||||
void setDirection(Direction d) {
|
||||
direc = d;
|
||||
layout->setDirection((QBoxLayout::Direction)d);
|
||||
}
|
||||
void setInvertedAppearance(bool yes) { slider->setInvertedAppearance(yes); }
|
||||
void setSquareScale(bool yes) {
|
||||
square = yes;
|
||||
adjust();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setMinimum(double value) {min_ = value; adjust();}
|
||||
void setMaximum(double value) {max_ = value; adjust();}
|
||||
void setSpinMinimum(double value) {spin->setMinimum(value);}
|
||||
void setSpinMaximum(double value) {spin->setMaximum(value);}
|
||||
void setValue(double value) {val_ = value; spin->setValue(value);}
|
||||
void setDecimals(int value) {dec_ = value; adjust();}
|
||||
void reset() {val_ = 0.; spin->setValue(0.);}
|
||||
void setMinimum(double value) {
|
||||
min_ = value;
|
||||
adjust();
|
||||
}
|
||||
void setMaximum(double value) {
|
||||
max_ = value;
|
||||
adjust();
|
||||
}
|
||||
void setSpinMinimum(double value) { spin->setMinimum(value); }
|
||||
void setSpinMaximum(double value) { spin->setMaximum(value); }
|
||||
void setValue(double value) {
|
||||
val_ = value;
|
||||
spin->setValue(value);
|
||||
}
|
||||
void setDecimals(int value) {
|
||||
dec_ = value;
|
||||
adjust();
|
||||
}
|
||||
void reset() {
|
||||
val_ = 0.;
|
||||
spin->setValue(0.);
|
||||
}
|
||||
|
||||
private:
|
||||
void adjust();
|
||||
double sqr(const double & v) {return v * v;}
|
||||
double sqr(const double & v) { return v * v; }
|
||||
|
||||
double min_, max_, val_, delim, page;
|
||||
int dec_, ticks_;
|
||||
@@ -112,7 +147,6 @@ private slots:
|
||||
signals:
|
||||
void valueChanged(double);
|
||||
void valueChangedInt(int);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user