git-svn-id: svn://db.shs.com.ru/libs@586 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-09-02 14:08:38 +00:00
parent f862381b68
commit 3d06d2095e
929 changed files with 66799 additions and 0 deletions

View File

@@ -0,0 +1 @@
qad_project(widgets "Gui;Widgets" "qad_utils")

View File

@@ -0,0 +1,151 @@
#include "chardialog.h"
#include "ui_chardialog.h"
CharDialog::CharDialog(QWidget * parent): QDialog(parent) {
ui = new Ui::CharDialog();
ui->setupUi(this);
QChar c;
int k;
for (int i = 0; i < 256; ++i) {
for (int j = 0; j < 256; ++j) {
c = QChar(j, i);
k = c.category();
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")
<< 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");
ui->comboCategory->addItems(cat);
ui->spinSize->setValue(size);
ui->comboCategory->setCurrentIndex(27);
ui->tableChars->viewport()->installEventFilter(this);
}
CharDialog::~CharDialog() {
delete ui;
}
void CharDialog::setCharFont(const QFont & f) {
QFont fnt = ui->tableChars->font();
fnt.setFamily(f.family());
ui->tableChars->setFont(fnt);
}
void CharDialog::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
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");
int pi = ui->comboCategory->currentIndex();
ui->comboCategory->clear();
ui->comboCategory->addItems(cat);
ui->comboCategory->setCurrentIndex(pi);
return;
}
QDialog::changeEvent(e);
}
bool CharDialog::eventFilter(QObject * o, QEvent * e) {
if (o == ui->tableChars->viewport()) {
if (e->type() != QEvent::Wheel)
return QDialog::eventFilter(o, e);
qApp->sendEvent(ui->verticalScroll, e);
}
return QDialog::eventFilter(o, e);
}
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);
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
if (ui->tableChars->item(i, j) == 0) {
ui->tableChars->setItem(i, j, new QTableWidgetItem());
ui->tableChars->item(i, j)->setTextAlignment(Qt::AlignCenter);
}
}
}
on_comboCategory_currentIndexChanged(ui->comboCategory->currentIndex());
}
void CharDialog::clear() {
for (int i = 0; i < ui->tableChars->rowCount(); ++i)
for (int j = 0; j < ui->tableChars->columnCount(); ++j)
ui->tableChars->item(i, j)->setText(QString());
}
void CharDialog::on_comboCategory_currentIndexChanged(int index) {
if (index < 0) return;
int r = ui->tableChars->rowCount(), c = ui->tableChars->columnCount(), m;
cur = &chars[index];
if (r == 0) return;
m = (cur->size() - 2) / c - r + 1;
if (m < 0) m = 0;
ui->verticalScroll->setMinimum(0);
ui->verticalScroll->setMaximum(m);
on_verticalScroll_valueChanged(ui->verticalScroll->value());
}
void CharDialog::on_verticalScroll_valueChanged(int index) {
int ci = ui->tableChars->columnCount() * 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());
}
}
}
void CharDialog::on_spinSize_valueChanged(int index) {
size = index;
csize = size * 2;
ui->tableChars->horizontalHeader()->setDefaultSectionSize(csize);
ui->tableChars->verticalHeader()->setDefaultSectionSize(csize);
on_comboCategory_currentIndexChanged(ui->comboCategory->currentIndex());
QFont font = ui->tableChars->font();
font.setPointSize(size);
ui->tableChars->setFont(font);
resizeEvent(0);
}
void CharDialog::on_tableChars_cellPressed(int row, int column) {
sel_char = ui->tableChars->item(row, column)->text()[0];
}
void CharDialog::on_buttonBox_accepted() {
emit charSelected(sel_char);
accept();
}

View File

@@ -0,0 +1,50 @@
#ifndef CHARDIALOG_H
#define CHARDIALOG_H
#include <QDialog>
#include <QMetaEnum>
#include <QDebug>
namespace Ui {
class CharDialog;
};
class CharDialog: public QDialog
{
Q_OBJECT
public:
explicit CharDialog(QWidget * parent = 0);
~CharDialog();
QChar selectedChar() {return sel_char;}
void setCharFont(const QFont & f);
public slots:
private:
void changeEvent(QEvent * e);
virtual bool eventFilter(QObject * o, QEvent * e);
virtual void resizeEvent(QResizeEvent * );
void clear();
Ui::CharDialog * ui;
QVector<QVector<QChar> > chars;
QVector<QChar> * cur;
QChar sel_char;
int size, csize;
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_buttonBox_accepted();
void on_buttonBox_rejected() {reject();}
signals:
void charSelected(QChar ch);
};
#endif // CHARDIALOG_H

View File

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CharDialog</class>
<widget class="QDialog" name="CharDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>448</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose symbol</string>
</property>
<property name="windowIcon">
<iconset resource="mbricks.qrc">
<normaloff>:/icons/icons/mbricks_128.png</normaloff>:/icons/icons/mbricks_128.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>2</number>
</property>
<property name="spacing">
<number>2</number>
</property>
<item row="0" column="0">
<widget class="QComboBox" name="comboCategory">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QTableWidget" name="tableChars">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>24</number>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>24</number>
</attribute>
</widget>
</item>
<item row="1" column="2">
<widget class="QScrollBar" name="verticalScroll">
<property name="maximum">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QSpinBox" name="spinSize">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="mbricks.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,67 @@
#include "clineedit.h"
#include "qad_types.h"
CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
cw = new QWidget(this);
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
cw->setCursor(Qt::ArrowCursor);
cw->setToolTip(tr("Clear"));
cw->hide();
cw->installEventFilter(this);
connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
int is = fontHeight();
int m0, m1, m2, m3;
getTextMargins(&m0, &m1, &m2, &m3);
setTextMargins(m0, m1, m2 + (is * 1.2), m3);
//connect(cw, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(clearMouseRelease(QMouseEvent * )));
}
bool CLineEdit::eventFilter(QObject * o, QEvent * e) {
switch (e->type()) {
case QEvent::MouseButtonRelease:
clearMouseRelease((QMouseEvent * )e);
break;
case QEvent::Paint:
cwPaintEvent();
break;
default : break;
}
return QLineEdit::eventFilter(o, e);
}
void CLineEdit::resizeEvent(QResizeEvent * e) {
QLineEdit::resizeEvent(e);
int is = fontHeight(), tm = (height() - is) / 2;
cw->setGeometry(width() - is - tm, tm, is, is);
}
void CLineEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
cw->setToolTip(tr("Clear"));
return;
}
QLineEdit::changeEvent(e);
}
void CLineEdit::cwPaintEvent() {
QPainter p(cw);
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.drawImage(cw->rect(), clear_im);
}
void CLineEdit::setDefaultText(const QString & t, bool set_text) {
dt = t;
if (set_text) {
setText(t);
emit textEdited(t);
cw->hide();
return;
}
textChanged_(text());
}

View File

@@ -0,0 +1,45 @@
#ifndef CLINEEDIT_H
#define CLINEEDIT_H
#include <QDebug>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
class CLineEdit: public QLineEdit
{
Q_OBJECT
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
public:
explicit CLineEdit(QWidget * parent = 0);
~CLineEdit() {delete cw;}
const QString & defaultText() const {return dt;}
protected:
QWidget * cw;
QString dt;
QImage clear_im;
private:
bool eventFilter(QObject * o, QEvent * e);
void resizeEvent(QResizeEvent * );
void changeEvent(QEvent * e);
void cwPaintEvent();
private slots:
void clearMouseRelease(QMouseEvent * e) {if (cw->rect().contains(e->pos())) clearClick();}
void textChanged_(QString text) {cw->setVisible(text != dt);}
public slots:
void clearClick() {if (!isEnabled()) return; setText(dt); emit cleared(); emit textEdited(dt);}
void setDefaultText(const QString & t, bool set_text = false);
signals:
void cleared();
};
#endif // CLINEEDIT_H

View File

@@ -0,0 +1,112 @@
#include "colorbutton.h"
#include <QDebug>
#include <QDrag>
#include <QMimeData>
ColorButton::ColorButton(QWidget * parent): QPushButton(parent) {
frame = false;
options = QColorDialog::ShowAlphaChannel;
back = new QWidget(this);
back->setAutoFillBackground(true);
back->show();
pal = back->palette();
pal.setBrush(back->backgroundRole(), QBrush(QImage(":/icons/alpha.png")));
back->setPalette(pal);
label = new QFrame(this);
label->setAutoFillBackground(true);
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
label->show();
pal = label->palette();
menu.addAction(QIcon(":/icons/edit-copy.png"), tr("Copy"), this, SLOT(copy()));
menu.addAction(QIcon(":/icons/edit-paste.png"), tr("Paste"), this, SLOT(paste()));
menu.addSeparator();
menu.addAction(tr("Mix with clipboard"), this, SLOT(mix()));
setAcceptDrops(true);
connect(this, SIGNAL(clicked(bool)), this, SLOT(clicked()));
}
ColorButton::~ColorButton() {
delete label;
}
void ColorButton::resizeEvent(QResizeEvent * ) {
if (frame) back->setGeometry(rect());
else back->setGeometry(8, 5, width() - 16, height() - 12);
label->setGeometry(back->geometry());
}
void ColorButton::mousePressEvent(QMouseEvent * e) {
pp = e->pos();
if (e->buttons().testFlag(Qt::RightButton)) {
menu.popup(e->globalPos());
return;
}
QPushButton::mousePressEvent(e);
}
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);
QMimeData * data = new QMimeData();
data->setColorData(color());
drag->setMimeData(data);
drag->exec(Qt::CopyAction);
return;
}
}
QPushButton::mouseMoveEvent(e);
}
void ColorButton::dragEnterEvent(QDragEnterEvent * e) {
e->accept();
QPushButton::dragEnterEvent(e);
}
void ColorButton::dropEvent(QDropEvent * e) {
const QMimeData * data = e->mimeData();
QColor c = qvariant_cast<QColor>(data->colorData());
if (c.isValid()) {
setColor(c);
return;
}
c = QColor(data->text());
if (c.isValid()) {
setColor(c);
return;
}
QPushButton::dropEvent(e);
}
void ColorButton::clicked() {
QColor ret = QColorDialog::getColor(color(), this, tr("Choose color"), options);
if (!ret.isValid()) return;
setColor(ret);
}
void ColorButton::mix() {
QColor c(QApplication::clipboard()->text());
if (!c.isValid()) return;
QColor sc = color();
setColor(QColor((c.red() + sc.red()) / 2, (c.green() + sc.green()) / 2, (c.blue() + sc.blue()) / 2, (c.alpha() + sc.alpha()) / 2));
}
void ColorButton::setColor(const QColor & col) {
if (pal.color(label->backgroundRole()) == col) return;
if (options.testFlag(QColorDialog::ShowAlphaChannel))
pal.setColor(label->backgroundRole(), col);
else
pal.setColor(label->backgroundRole(), QColor(col.red(), col.green(), col.blue()));
label->setPalette(pal);
emit colorChanged(color());
}

View File

@@ -0,0 +1,63 @@
#ifndef COLORBUTTON_H
#define COLORBUTTON_H
#include <QPushButton>
#include <QFrame>
#include <QColorDialog>
#include <QMouseEvent>
#include <QAction>
#include <QMenu>
#include <QClipboard>
#include <QApplication>
class 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 = 0);
~ColorButton();
QColor color() const {return pal.color(label->backgroundRole());}
bool useNativeDialog() const {return !options.testFlag(QColorDialog::DontUseNativeDialog);}
bool useAlphaChannel() const {return options.testFlag(QColorDialog::ShowAlphaChannel);}
bool frameOnly() const {return frame;}
public slots:
void setColor(const QColor & col);
void setUseNativeDialog(bool yes) {if (yes) options &= ~QColorDialog::DontUseNativeDialog; else options |= QColorDialog::DontUseNativeDialog;}
void setUseAlphaChannel(bool yes) {if (yes) options |= QColorDialog::ShowAlphaChannel; else options &= ~QColorDialog::ShowAlphaChannel;}
void setFrameOnly(bool yes) {frame = yes; setFlat(frame); resizeEvent(0);}
private:
void mousePressEvent(QMouseEvent * e);
void mouseMoveEvent(QMouseEvent * e);
void resizeEvent(QResizeEvent * );
void dragEnterEvent(QDragEnterEvent * e);
void dropEvent(QDropEvent * e);
QFrame * label;
QWidget * back;
QPalette pal;
QPoint pp;
QMenu menu;
QColorDialog::ColorDialogOptions options;
bool frame;
private slots:
void clicked();
void copy() {QApplication::clipboard()->setText(color().name());}
void paste() {QColor c(QApplication::clipboard()->text()); if (c.isValid()) setColor(c);}
void mix();
signals:
void colorChanged(QColor);
};
#endif // COLORBUTTON_H

View File

@@ -0,0 +1,102 @@
#include <QStandardItemModel>
#include <QApplication>
#include <QDebug>
#include <QHeaderView>
#include "ecombobox.h"
#include "qad_types.h"
class EModel: public QStandardItemModel {
public:
EModel(QObject * parent = 0): QStandardItemModel(parent) {
#if QT_VERSION < 0x050000
setSupportedDragActions(Qt::MoveAction);
#endif
}
protected:
virtual Qt::ItemFlags flags(const QModelIndex & index) const {
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
if (!index.isValid()) f |= Qt::ItemIsDropEnabled;
return f;
}
#if QT_VERSION >= 0x050000
Qt::DropActions supportedDragActions() const {return Qt::MoveAction;}
#endif
};
EComboBox::EComboBox(QWidget * parent): QComboBox(parent) {
setView(&iv);
setModel(new EModel());
iv.setTextElideMode(Qt::ElideMiddle);
iv.setRootIsDecorated(false);
iv.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
iv.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
iv.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
iv.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
iv.setDragDropMode(QAbstractItemView::InternalMove);
iv.setMinimumHeight(100);
icon.setPixmap(QPixmap(":/icons/edit-find.png"));
icon.setScaledContents(true);
icon.setFixedSize(preferredIconSize(1.2, this));
ifont = nfont = font();
ifont.setItalic(true);
#if QT_VERSION >= 0x040700
filter.setPlaceholderText(tr("Filter"));
filter.setFont(ifont);
#endif
header.setAutoFillBackground(true);
header.setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
header.layout()->setSpacing(2);
header.layout()->setContentsMargins(2, 0, 0, 0);
header.layout()->addWidget(&icon);
header.layout()->addWidget(&filter);
header.setParent(iv.header());
connect(&filter, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
}
QSize EComboBox::sizeHint() const {
QSize s = QComboBox::sizeHint();
s.setWidth(s.width() + 16);
return s;
}
void EComboBox::showPopup() {
filterChanged(filter.text(), true);
QComboBox::showPopup();
QRect r = iv.header()->rect();
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
filter.setFocus();
}
void EComboBox::filterChanged(const QString & text, bool first) {
if (filter.text().isEmpty()) filter.setFont(ifont);
else filter.setFont(nfont);
iv.hide();
QModelIndex pi = iv.rootIndex();
if (text.isEmpty()) {
for (int i = 0; i < iv.model()->rowCount(); ++i) {
iv.setRowHidden(i, pi, false);
iv.model()->setData(iv.model()->index(i, 0), iv.model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole);
}
iv.show();
if (first) return;
hidePopup();
showPopup();
qApp->processEvents();
QRect r = iv.header()->rect();
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
return;
}
for (int i = 0; i < iv.model()->rowCount(); ++i) {
iv.setRowHidden(i, pi, !iv.model()->index(i, 0, pi).data().toString().contains(QRegExp(text, Qt::CaseInsensitive)));
iv.model()->setData(iv.model()->index(i, 0), iv.model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole);
}
iv.show();
qApp->processEvents();
QRect r = iv.header()->rect();
header.setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
}

View File

@@ -0,0 +1,36 @@
#ifndef ECOMBOBOX_H
#define ECOMBOBOX_H
#include <QComboBox>
#include <QBoxLayout>
#include <QTreeView>
#include <QLabel>
#include "clineedit.h"
class EComboBox: public QComboBox
{
Q_OBJECT
public:
explicit EComboBox(QWidget * parent = 0);
QSize sizeHint() const;
public slots:
virtual void showPopup();
private:
QTreeView iv;
QWidget header;
QLabel icon;
CLineEdit filter;
QFont nfont, ifont;
private slots:
void filterChanged(const QString & text, bool first = false);
signals:
};
#endif // ECOMBOBOX_H

View File

@@ -0,0 +1,337 @@
#include "evalspinbox.h"
#include <QLineEdit>
#include <QLabel>
#include <QDebug>
#include <QRegExp>
#include <QPainter>
#include <QTimer>
#include <QStyle>
#include <QStyleOptionSpinBox>
#include "qad_types.h"
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
status = new QWidget(lineEdit());
cw = new QWidget(lineEdit());
label = new QLabel(lineEdit());
// label->hide();
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
icon_ok.load(":/icons/dialog-ok-apply.png");
icon_fail.load(":/icons/dialog-warning.png");
icon_calc.load(":/icons/tools-wizard.png");
icon = icon_ok;
status->setCursor(Qt::ArrowCursor);
status->setToolTip("OK -> 0");
status->hide();
cw->setCursor(Qt::ArrowCursor);
cw->setToolTip(tr("Clear"));
cw->hide();
cw_visible = false;
//lineEdit()->setStyleSheet("color: darkgreen;");
//lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
cw->installEventFilter(this);
status->installEventFilter(this);
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
connect(this, SIGNAL(editingFinished()), this, SLOT(setExpression_()));
label->setText("0");
//connect(cw, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(clearMouseRelease(QMouseEvent * )));
}
EvalSpinBox::~EvalSpinBox() {
delete cw;
delete status;
delete label;
}
bool EvalSpinBox::eventFilter(QObject * o, QEvent * e) {
switch (e->type()) {
case QEvent::MouseButtonRelease:
if (o == cw) clearMouseRelease((QMouseEvent * )e);
break;
case QEvent::Paint:
if (o == status) statusPaintEvent();
if (o == cw) cwPaintEvent();
break;
default : break;
}
return QAbstractSpinBox::eventFilter(o, e);
}
void EvalSpinBox::resizeIcons() {
int is = fontHeight();
int tm = (lineEdit()->height() - is + 1) / 2;
QStyleOptionFrame so;
so.initFrom(lineEdit());
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &so, lineEdit());
int m0, m1, m2, m3;
lineEdit()->getTextMargins(&m0, &m1, &m2, &m3);
//label->setGeometry(m0 + r.x() + 2, m1 + r.y() + (r.height() - fontMetrics().height() + 1) / 2, lineEdit()->width() - 2*tm - (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)), lineEdit()->height() - 2*tm);
int lwh = label->sizeHint().width();
label->setGeometry(lineEdit()->width() - m0 - lwh + r.x() - 2,
m1 + 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);
lineEdit()->setTextMargins(m0, m1, (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)), m3);
}
void EvalSpinBox::resizeEvent(QResizeEvent * e) {
QAbstractSpinBox::resizeEvent(e);
resizeIcons();
}
void EvalSpinBox::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
cw->setToolTip(tr("Clear"));
return;
}
QAbstractSpinBox::changeEvent(e);
}
void EvalSpinBox::cwPaintEvent() {
QPainter p(cw);
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.drawImage(cw->rect(), clear_im);
}
void EvalSpinBox::statusPaintEvent() {
QPainter p(status);
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.drawImage(status->rect(), icon);
}
void EvalSpinBox::clearMouseRelease(QMouseEvent * e) {
if (cw->rect().contains(e->pos())) clear();
}
void EvalSpinBox::textChanged_(const QString & text) {
double pv = value();
QString t = text;
cw->setVisible(text != dt && cw_visible);
bool td = false;
if (t.endsWith('=')) {
td = true;
t.chop(1);
}
bool ok = eval.check(t);
if (ok) {
eval.evaluate();
if (td) {
icon = icon_calc;
status->setToolTip("Enter to calc -> "+QString::number(value(), 'G', 10));
} else {
icon = icon_ok;
status->setToolTip("OK -> "+QString::number(value(), 'G', 10));
}
// qDebug() << "value =" << value();
if (pv != value()) emit valueChanged(value());
} else {
icon = icon_fail;
status->setToolTip(eval.error());
}
resizeIcons();
}
void EvalSpinBox::setExpression_() {
bool td = false;
double pv = value();
QString t = text();
if (t.endsWith('=')) {
td = true;
t.chop(1);
}
if (eval.check(t)) {
/*if (eval.expression() == "0") lineEdit()->clear();
else*/ lineEdit()->setText(eval.expression());
eval.evaluate();
if (td) lineEdit()->setText(QString::number(value(), 'G', 10));
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
icon = icon_ok;
} else {
icon = icon_fail;
status->setToolTip(eval.error());
// qDebug() << eval.expression();
}
if (!label->isHidden()) {
// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
// else
// label->setText(eval.expression());
if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
else
label->setText("");
lineEdit()->blockSignals(true);
if (!eval.isCorrect()) {
lineEdit()->setStyleSheet("color: darkred;");
status->show();
} else {
lineEdit()->setStyleSheet("");
status->hide();
}
// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
//lineEdit()->setText("");
lineEdit()->blockSignals(false);
}
// qDebug() << "value =" << value();
if (pv != value()) emit valueChanged(value());
}
void EvalSpinBox::setExpression(const QString & expr) {
lineEdit()->setText(expr);
//if (eval.expression() == "0") lineEdit()->clear();
cw->setVisible(text() != dt && cw_visible);
setExpression_();
}
void EvalSpinBox::setValue(double val) {
lineEdit()->setText(QString::number(val, 'G', 16));
//if (val == 0) lineEdit()->clear();
cw->setVisible(text() != dt && cw_visible);
setExpression_();
}
void EvalSpinBox::stepBy(int steps) {
stepByDouble(steps);
}
void EvalSpinBox::clear() {
lineEdit()->setText(dt);
setExpression_();
cw->hide();
resizeIcons();
emit cleared();
}
double EvalSpinBox::value() const {
if (eval.isCorrect()) {
return eval.lastResult().real();
}
return 0.;
}
const QString & EvalSpinBox::expression() const {
return eval.expression();
}
bool EvalSpinBox::isCleared() const {
return (dt == eval.expression() || (value() == 0 && dt.isEmpty()));
}
QSize EvalSpinBox::sizeHint() const {
QSize s = QAbstractSpinBox::sizeHint();
s.setWidth(120);
return s;
}
QAbstractSpinBox::StepEnabled EvalSpinBox::stepEnabled() const {
return StepUpEnabled | StepDownEnabled;
}
void EvalSpinBox::focusInEvent(QFocusEvent * event) {
// qDebug() << "focus_in";
label->hide();
status->show();
lineEdit()->blockSignals(true);
lineEdit()->setStyleSheet("");
if (eval.expression() == "0") lineEdit()->clear();
lineEdit()->blockSignals(false);
QAbstractSpinBox::focusInEvent(event);
resizeIcons();
}
void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
QAbstractSpinBox::focusOutEvent(event);
// qDebug() << eval.expression() << QString::number(value(), 'G', 10);
// if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
// else
// label->setText(eval.expression());
if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
else
label->setText("");
label->show();
lineEdit()->blockSignals(true);
if (!eval.isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
else status->hide();
// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
//lineEdit()->clear();
lineEdit()->blockSignals(false);
resizeIcons();
}
void EvalSpinBox::wheelEvent(QWheelEvent * event) {
if (event->modifiers().testFlag(Qt::ShiftModifier))
stepByDouble(event->delta() > 0 ? 0.1 : -0.1);
else
QAbstractSpinBox::wheelEvent(event);
}
void EvalSpinBox::stepByDouble(double steps) {
//qDebug() << "step" << steps;
if (isReadOnly()) return;
QString t = text();
if (eval.check(t)) {
t = eval.expression();
//QRegExp re("(\\-?\\d+)");
QRegExp re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)");
int pos = 0;
if ((pos = re.indexIn(t)) != -1) {
double v = t.mid(pos, re.matchedLength()).toDouble();
v += steps;
t.remove(pos, re.matchedLength());
t.insert(pos, QString::number(v));
} else {
double v = steps;
t = QString::number(v) + t;
}
eval.check(t);
lineEdit()->setText(eval.expression());
}
}
void EvalSpinBox::setDefaultText(const QString & t) {
// bool def = (!cw->isHidden());
dt = t;
// if (def) {
// lineEdit()->setText(dt);
// setExpression_();
// }
//if (t == eval.expression() || (value() == 0 && t.isEmpty())) clear();
cw->setVisible((eval.expression() != dt || (dt.isEmpty() && eval.expression() == "0")) && cw_visible);
resizeIcons();
}
void EvalSpinBox::setClearButtonVisible(bool visible) {
cw_visible = visible;
cw->setVisible((eval.expression() != dt || (dt.isEmpty() && eval.expression() == "0")) && cw_visible);
resizeIcons();
}

View File

@@ -0,0 +1,79 @@
#ifndef EVALSPINBOX_H
#define EVALSPINBOX_H
#include <QAbstractSpinBox>
#include <QMouseEvent>
#include "qpievaluator.h"
class QLabel;
class 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)
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
Q_PROPERTY(bool clearButtonVisible READ isClearButtonVisible WRITE setClearButtonVisible)
public:
explicit EvalSpinBox(QWidget * parent = 0);
~EvalSpinBox();
double value() const;
const QString & expression() const;
const QString & defaultText() const {return dt;}
bool isClearButtonVisible() const {return cw_visible;}
bool isCleared() const;
virtual void stepBy(int steps);
virtual void clear();
virtual QSize sizeHint() const;
public slots:
void setExpression(const QString & expr);
void setValue(double val);
void setDefaultText(const QString & t);
void setClearButtonVisible(bool visible);
protected:
QString text() const {return QAbstractSpinBox::text();}
virtual StepEnabled stepEnabled() const;
virtual void focusInEvent(QFocusEvent *event);
virtual void focusOutEvent(QFocusEvent *event);
virtual void wheelEvent(QWheelEvent *event);
void stepByDouble(double steps);
QWidget * status;
QWidget * cw;
QPIEvaluator eval;
QLabel * label;
QImage icon_ok;
QImage icon_fail;
QImage icon_calc;
QImage icon;
QImage clear_im;
QString dt;
bool cw_visible;
private:
bool eventFilter(QObject * o, QEvent * e);
void resizeEvent(QResizeEvent * );
void changeEvent(QEvent * e);
void statusPaintEvent();
void cwPaintEvent();
private slots:
void clearMouseRelease(QMouseEvent * e);
void textChanged_(const QString & text);
void setExpression_();
void resizeIcons();
signals:
void valueChanged(double val);
void cleared();
};
#endif // EVALSPINBOX_H

View File

@@ -0,0 +1,59 @@
#include "iconedlabel.h"
#include "qad_types.h"
#include <QHBoxLayout>
#include <QEvent>
IconedLabel::IconedLabel(QWidget * parent): QFrame(parent) {
label_.setAlignment(Qt::AlignCenter);
icon_.setAlignment(Qt::AlignCenter);
icon_.setScaledContents(true);
setIconSize(QSize());
setDirection(RightToLeft);
}
QIcon IconedLabel::icon() const {
return icon_.pixmap() == 0 ? QIcon() : QIcon(*icon_.pixmap());
}
bool IconedLabel::event(QEvent * e) {
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish)
setIconSize(iconSize());
return QFrame::event(e);
}
QSize IconedLabel::realIconSize() const {
return size_.isValid() ? size_ : preferredIconSize(1.f, this);
}
void IconedLabel::setIcon(const QIcon & i) {
sicon_ = i;
setIconSize(iconSize());
}
void IconedLabel::setIconSize(const QSize & s) {
size_ = s;
QSize sz = realIconSize();
icon_.setPixmap(sicon_.pixmap(sz));
icon_.setFixedSize(sz);
}
void IconedLabel::setDirection(IconedLabel::Direction d) {
dir_ = d;
if (layout() != 0)
delete layout();
QLayout * lay = new QBoxLayout((QBoxLayout::Direction)dir_);
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
lay->addWidget(&label_);
lay->addWidget(&icon_);
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
lay->setContentsMargins(0, 0, 0, 0);
setLayout(lay);
update();
}

View File

@@ -0,0 +1,53 @@
#ifndef ICONEDLABEL_H
#define ICONEDLABEL_H
#include <QLabel>
#include <QIcon>
#include "qad_types.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class 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};
explicit IconedLabel(QWidget * parent = 0);
QString text() const {return label_.text();}
QIcon icon() const;
QSize iconSize() const {return size_;}
Direction direction() const {return dir_;}
protected:
virtual bool event(QEvent * e);
QSize realIconSize() const;
QLabel label_, icon_;
QIcon sicon_;
QSize size_;
Direction dir_;
public slots:
void setText(const QString & t) {label_.setText(t);}
void setIcon(const QIcon & i);
void setIconSize(const QSize & s);
void setDirection(Direction d);
signals:
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // ICONEDLABEL_H

View File

@@ -0,0 +1,134 @@
#include "image_view.h"
#include <QGraphicsScene>
#include <QBuffer>
#include <QEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QDebug>
#include <qmath.h>
ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setDragMode(QGraphicsView::NoDrag);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setScene(new QGraphicsScene());
item.setTransformationMode(Qt::SmoothTransformation);
item.setFlags(0);
scene()->addItem(&item);
viewport()->setAutoFillBackground(false);
viewport()->installEventFilter(this);
autofit_ = true;
}
ImageView::~ImageView() {
}
QPixmap ImageView::pixmap() const {
return item.pixmap();
}
void ImageView::setPixmap(QPixmap pixmap) {
item.setPixmap(pixmap);
adjustView();
}
void ImageView::setImage(const QImage & i) {
im_data.clear();
if (i.isNull()) {
item.setPixmap(QPixmap());
return;
}
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
i.save(&b, "png");
b.close();
item.setPixmap(QPixmap::fromImage(i));
adjustView();
}
void ImageView::setImage(const QByteArray & i) {
im_data = i;
if (i.isEmpty()) {
item.setPixmap(QPixmap());
return;
}
item.setPixmap(QPixmap::fromImage(QImage::fromData(i)));
adjustView();
}
void ImageView::clear() {
im_data.clear();
item.setPixmap(QPixmap());
}
void ImageView::mouseDoubleClickEvent(QMouseEvent * e) {
autofit();
}
void ImageView::mousePressEvent(QMouseEvent * e) {
QGraphicsView::mousePressEvent(e);
emit clicked(mapToScene(e->pos()), e->buttons());
}
void ImageView::mouseMoveEvent(QMouseEvent * e) {
//if (e->buttons().testFlag(Qt::RightButton) && !autofit_ && isInteractive()) return;;
QGraphicsView::mouseMoveEvent(e);
}
void ImageView::wheelEvent(QWheelEvent * e) {
if (!e->modifiers().testFlag(Qt::ControlModifier) || !isInteractive()) return;
double scl = 1. + e->delta() / 500.;
//autofit_ = false;
//scale(scl, scl);
}
bool ImageView::eventFilter(QObject * o, QEvent * e) {
QMouseEvent * me = (QMouseEvent *)e;
switch (e->type()) {
case QEvent::Resize:
adjustView();
break;
case QEvent::MouseButtonPress:
prev_pos = me->pos();
break;
case QEvent::MouseMove:
if (!me->buttons().testFlag(Qt::RightButton) || autofit_ || !isInteractive()) break;
{
double scl = 1. / qSqrt(transform().determinant());
QPointF dp = QPointF(me->pos() - prev_pos) * scl;
//qDebug() << dp;
//translate(0.00001, 0);
prev_pos = me->pos();
}
break;
default: break;
}
return QGraphicsView::eventFilter(o, e);
}
void ImageView::adjustView() {
if (!autofit_) return;
setSceneRect(item.boundingRect());
fitInView(&item, Qt::KeepAspectRatio);
centerOn(&item);
}
void ImageView::autofit() {
autofit_ = true;
adjustView();
}

View File

@@ -0,0 +1,46 @@
#ifndef IMAGE_VIEW_H
#define IMAGE_VIEW_H
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
class ImageView: public QGraphicsView
{
Q_OBJECT
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
public:
ImageView(QWidget * parent = 0);
~ImageView();
void setImage(const QImage & i);
void setImage(const QByteArray & i);
QByteArray image() const {return im_data;}
QPixmap pixmap() const;
void clear();
private:
void mouseDoubleClickEvent(QMouseEvent * e);
void mousePressEvent(QMouseEvent * e);
void mouseMoveEvent(QMouseEvent * e);
void wheelEvent(QWheelEvent * e);
bool eventFilter(QObject * o, QEvent * e);
void adjustView();
QGraphicsPixmapItem item;
QByteArray im_data;
QPoint prev_pos;
bool autofit_;
public slots:
void autofit();
void setPixmap(QPixmap pixmap);
signals:
void clicked(QPointF, Qt::MouseButtons);
};
#endif // IMAGE_VIEW_H

View File

@@ -0,0 +1,607 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
<name>CLineEdit</name>
<message>
<location filename="../clineedit.cpp" line="8"/>
<location filename="../clineedit.cpp" line="35"/>
<source>Clear</source>
<translation>Сбросить</translation>
</message>
</context>
<context>
<name>CharDialog</name>
<message>
<location filename="../chardialog.ui" line="14"/>
<source>Choose symbol</source>
<translation>Выбрать символ</translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="54"/>
<source>No Category</source>
<translation>Вне категории</translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="54"/>
<source>Mark NonSpacing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="54"/>
<source>Mark SpacingCombining</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="54"/>
<source>Mark Enclosing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="55"/>
<source>Number DecimalDigit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="55"/>
<source>Number Letter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="55"/>
<source>Number Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="55"/>
<source>Separator Space</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="56"/>
<source>Separator Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="56"/>
<source>Separator Paragraph</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="56"/>
<source>Other Control</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="56"/>
<source>Other Format</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="57"/>
<source>Other Surrogate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="57"/>
<source>Other PrivateUse</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="57"/>
<source>Other NotAssigned</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="57"/>
<source>Letter Uppercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="58"/>
<source>Letter Lowercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="58"/>
<source>Letter Titlecase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="58"/>
<source>Letter Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="58"/>
<source>Letter Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="59"/>
<source>Punctuation Connector</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="59"/>
<source>Punctuation Dash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="59"/>
<source>Punctuation Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="59"/>
<source>Punctuation Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="29"/>
<location filename="../chardialog.cpp" line="60"/>
<source>Punctuation InitialQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="29"/>
<location filename="../chardialog.cpp" line="60"/>
<source>Punctuation FinalQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="29"/>
<location filename="../chardialog.cpp" line="60"/>
<source>Punctuation Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="29"/>
<location filename="../chardialog.cpp" line="60"/>
<source>Symbol Math</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="30"/>
<location filename="../chardialog.cpp" line="61"/>
<source>Symbol Currency</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="30"/>
<location filename="../chardialog.cpp" line="61"/>
<source>Symbol Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="30"/>
<location filename="../chardialog.cpp" line="61"/>
<source>Symbol Other</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ColorButton</name>
<message>
<location filename="../colorbutton.cpp" line="20"/>
<source>Copy</source>
<translation>Копировать</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="21"/>
<source>Paste</source>
<translation>Вставить</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="23"/>
<source>Mix with clipboard</source>
<translation>Смешать со скопированным</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="90"/>
<source>Choose color</source>
<translation>Выбрать цвет</translation>
</message>
</context>
<context>
<name>EComboBox</name>
<message>
<location filename="../ecombobox.cpp" line="42"/>
<source>Filter</source>
<translation>Фильтр</translation>
</message>
</context>
<context>
<name>PathEdit</name>
<message>
<location filename="../qvariantedit.cpp" line="105"/>
<source>All files(*)</source>
<translation>Все файлы(*)</translation>
</message>
<message>
<location filename="../qvariantedit.cpp" line="111"/>
<location filename="../qvariantedit.cpp" line="123"/>
<source>Choose</source>
<translation>Выберите</translation>
</message>
<message>
<location filename="../qvariantedit.cpp" line="132"/>
<source>Select directory</source>
<translation>Выберите директорию</translation>
</message>
<message>
<location filename="../qvariantedit.cpp" line="133"/>
<source>Select file</source>
<translation>Выберите файл</translation>
</message>
</context>
<context>
<name>QCodeEdit</name>
<message>
<location filename="../qcodeedit.cpp" line="40"/>
<source>Press F1 for details</source>
<translation>Нажмите F1 для справочной информации</translation>
</message>
</context>
<context>
<name>QPIConfigNewDialog</name>
<message>
<location filename="../qpiconfignewdialog.ui" line="20"/>
<source>Dialog</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="26"/>
<source>Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="32"/>
<source>string</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="38"/>
<source>s</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="45"/>
<source>integer</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="48"/>
<source>n</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="55"/>
<source>float</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="58"/>
<source>f</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="65"/>
<source>string list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="68"/>
<source>l</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="75"/>
<source>boolean</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="78"/>
<source>b</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="85"/>
<source>color</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="88"/>
<source>c</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="95"/>
<source>rectangle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="98"/>
<source>r</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="105"/>
<source>area</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="108"/>
<source>a</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="115"/>
<source>point</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="118"/>
<source>p</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="125"/>
<source>vector</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="128"/>
<source>v</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="135"/>
<source>ip</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="138"/>
<source>i</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="148"/>
<source>Name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="181"/>
<source>Comment:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfignewdialog.ui" line="191"/>
<source>Value:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QPIConfigWidget</name>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Name</source>
<translation>Имя</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Value</source>
<translation>Значение</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Type</source>
<translation>Тип</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Comment</source>
<translation>Описание</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="345"/>
<source>string</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="346"/>
<source>string list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="347"/>
<source>integer</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="348"/>
<source>float</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="349"/>
<source>boolean</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="350"/>
<source>color</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="351"/>
<source>rectangle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="352"/>
<source>area</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="353"/>
<source>point</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="354"/>
<source>vector</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="355"/>
<source>ip</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="356"/>
<source>Add item ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="357"/>
<source>Add node ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="358"/>
<source>Convert to item</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="359"/>
<source>Convert to node</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="360"/>
<source>Remove</source>
<translation>Удалить</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="361"/>
<source>Expand all</source>
<translation>Свернуть все</translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="362"/>
<source>Collapse all</source>
<translation>Развернуть все</translation>
</message>
</context>
<context>
<name>QPointEdit</name>
<message>
<location filename="../qpointedit.cpp" line="12"/>
<location filename="../qpointedit.cpp" line="29"/>
<source>X</source>
<translation></translation>
</message>
<message>
<location filename="../qpointedit.cpp" line="13"/>
<location filename="../qpointedit.cpp" line="30"/>
<source>Y</source>
<translation></translation>
</message>
</context>
<context>
<name>QRectEdit</name>
<message>
<location filename="../qrectedit.cpp" line="18"/>
<location filename="../qrectedit.cpp" line="49"/>
<source>X</source>
<translation></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="19"/>
<location filename="../qrectedit.cpp" line="50"/>
<source>Y</source>
<translation></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="20"/>
<location filename="../qrectedit.cpp" line="51"/>
<source>Height</source>
<translation>Высота</translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="21"/>
<location filename="../qrectedit.cpp" line="52"/>
<source>Width</source>
<translation>Ширина</translation>
</message>
</context>
<context>
<name>QVariantEdit</name>
<message>
<location filename="../qvariantedit.cpp" line="176"/>
<source>Invalid value</source>
<translation>Неверное значение</translation>
</message>
</context>
<context>
<name>Shortcuts</name>
<message>
<location filename="../shortcuts.cpp" line="38"/>
<location filename="../shortcuts.cpp" line="54"/>
<source>Command</source>
<translation>Команда</translation>
</message>
<message>
<location filename="../shortcuts.cpp" line="38"/>
<location filename="../shortcuts.cpp" line="54"/>
<source>Shortcut</source>
<translation>Горячая клавиша</translation>
</message>
</context>
<context>
<name>StringListEdit</name>
<message>
<location filename="../qvariantedit.cpp" line="67"/>
<location filename="../qvariantedit.cpp" line="85"/>
<source>Add</source>
<translation>Добавить</translation>
</message>
<message>
<location filename="../qvariantedit.cpp" line="68"/>
<location filename="../qvariantedit.cpp" line="86"/>
<source>Remove</source>
<translation>Удалить</translation>
</message>
<message>
<location filename="../qvariantedit.cpp" line="69"/>
<location filename="../qvariantedit.cpp" line="87"/>
<source>Clear</source>
<translation>Очистить</translation>
</message>
</context>
</TS>

View File

@@ -0,0 +1,53 @@
#include "mathmatrixedit.h"
#include "qvariantedit_custom.h"
#include "matrixedit.h"
#include <QBoxLayout>
MathMatrixEdit::MathMatrixEdit(QWidget * parent): QWidget(parent) {
edit = new MatrixEdit();
setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(edit);
connect(edit, SIGNAL(changed()), this, SIGNAL(valueChanged()));
}
MathMatrixEdit::~MathMatrixEdit() {
delete edit;
}
QVariant MathMatrixEdit::value() const {
return QVariant::fromValue(QAD::MathMatrix(edit->matrix()));
}
bool MathMatrixEdit::isReadOnly() const {
return edit->isReadOnly();
}
void MathMatrixEdit::setValue(const QVariant & v) {
edit->setMatrix(v.value<QAD::MathMatrix>().m);
}
void MathMatrixEdit::setReadOnly(bool yes) {
edit->setReadOnly(yes);
}
class MathMatrixEditFactory: public QVariantEditorFactoryBase {
public:
MathMatrixEditFactory() {}
virtual QWidget * createEditor() {return new MathMatrixEdit();}
};
__MathMatrixEditRegistrator__::__MathMatrixEditRegistrator__() {
QVariantEditorFactories::registerEditorFactory(qMetaTypeId<QAD::MathMatrix>(), new MathMatrixEditFactory());
//__QADTypesRegistrator__::instance()->toString_funcs.insert(qMetaTypeId<QAD::IODevice>(), &QAD_IODevice_toString);
}

View File

@@ -0,0 +1,40 @@
#ifndef MATH_MATRIX_EDIT_H
#define MATH_MATRIX_EDIT_H
#include <QWidget>
#include "qad_types.h"
class MatrixEdit;
class 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 = 0);
~MathMatrixEdit();
QVariant value() const;
bool isReadOnly() const;
private:
MatrixEdit * edit;
public slots:
void setValue(const QVariant & v);
void setReadOnly(bool yes);
signals:
void valueChanged();
};
class __MathMatrixEditRegistrator__ {
public:
__MathMatrixEditRegistrator__();
};
static __MathMatrixEditRegistrator__ __mathmatrixeditregistrator__;
#endif // MATH_MATRIX_EDIT_H

View File

@@ -0,0 +1,53 @@
#include "mathvectoredit.h"
#include "qvariantedit_custom.h"
#include "matrixedit.h"
#include <QBoxLayout>
MathVectorEdit::MathVectorEdit(QWidget * parent): QWidget(parent) {
edit = new MatrixEdit();
setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(edit);
connect(edit, SIGNAL(changed()), this, SIGNAL(valueChanged()));
}
MathVectorEdit::~MathVectorEdit() {
delete edit;
}
QVariant MathVectorEdit::value() const {
return QVariant::fromValue(QAD::MathVector(edit->vector()));
}
bool MathVectorEdit::isReadOnly() const {
return edit->isReadOnly();
}
void MathVectorEdit::setValue(const QVariant & v) {
edit->setVector(v.value<QAD::MathVector>().v);
}
void MathVectorEdit::setReadOnly(bool yes) {
edit->setReadOnly(yes);
}
class MathVectorEditFactory: public QVariantEditorFactoryBase {
public:
MathVectorEditFactory() {}
virtual QWidget * createEditor() {return new MathVectorEdit();}
};
__MathVectorEditRegistrator__::__MathVectorEditRegistrator__() {
QVariantEditorFactories::registerEditorFactory(qMetaTypeId<QAD::MathVector>(), new MathVectorEditFactory());
//__QADTypesRegistrator__::instance()->toString_funcs.insert(qMetaTypeId<QAD::IODevice>(), &QAD_IODevice_toString);
}

View File

@@ -0,0 +1,40 @@
#ifndef MATH_VECTOR_EDIT_H
#define MATH_VECTOR_EDIT_H
#include <QWidget>
#include "qad_types.h"
class MatrixEdit;
class 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 = 0);
~MathVectorEdit();
QVariant value() const;
bool isReadOnly() const;
private:
MatrixEdit * edit;
public slots:
void setValue(const QVariant & v);
void setReadOnly(bool yes);
signals:
void valueChanged();
};
class __MathVectorEditRegistrator__ {
public:
__MathVectorEditRegistrator__();
};
static __MathVectorEditRegistrator__ __mathvectoreditregistrator__;
#endif // MATH_VECTOR_EDIT_H

View File

@@ -0,0 +1,149 @@
#include "matrixedit.h"
#include "ui_matrixedit.h"
#include <QBoxLayout>
MatrixEdit::MatrixEdit(QWidget * parent): QWidget(parent) {
ui = new Ui::MatrixEdit();
ui->setupUi(this);
connect(ui->table, SIGNAL(cellChanged(int,int)), this, SIGNAL(changed()));
ro = false;
}
MatrixEdit::~MatrixEdit() {
delete ui;
}
bool MatrixEdit::isReadOnly() const {
return ro;
}
void MatrixEdit::setReadOnly(bool yes) {
ro = yes;
/// TODO
}
void MatrixEdit::setVectorMode(bool yes) {
if (yes)
ui->spinCols->setValue(1);
ui->labelCols->setHidden(yes);
ui->spinCols->setHidden(yes);
ui->buttonIdentity->setHidden(yes);
}
void MatrixEdit::clear(bool ident) {
int cc = ui->table->columnCount();
for (int r = 0; r < ui->table->rowCount(); ++r) {
for (int c = 0; c < cc; ++c) {
QTableWidgetItem * i = ui->table->item(r, c);
if (!i) {
i = new QTableWidgetItem();
ui->table->setItem(r, c, i);
}
i->setText((ident && (r == c)) ? "1" : "0");
}
}
}
QVector<double> MatrixEdit::vector() const {
QVector<double> ret;
if (ui->table->columnCount() < 1) return ret;
ret.resize(ui->table->rowCount());
ret.fill(0.);
for (int r = 0; r < ret.size(); ++r) {
QTableWidgetItem * i = ui->table->item(r, 0);
if (!i) continue;
ret[r] = i->text().toDouble();
}
return 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());
for (int r = 0; r < ret.size(); ++r) {
ret[r].resize(cc);
ret[r].fill(0.);
for (int c = 0; c < cc; ++c) {
QTableWidgetItem * i = ui->table->item(r, c);
if (!i) continue;
ret[r][c] = i->text().toDouble();
}
}
return ret;
}
void MatrixEdit::setVector(const QVector<double> & v) {
clear();
if (v.isEmpty()) return;
blockSignals(true);
ui->spinRows->setValue(v.size());
setVectorMode(true);
for (int r = 0; r < v.size(); ++r) {
QTableWidgetItem * i = ui->table->item(r, 0);
if (!i) {
i = new QTableWidgetItem();
ui->table->setItem(r, 0, i);
}
i->setText(QString::number(v[r]));
}
blockSignals(false);
emit changed();
}
void MatrixEdit::setMatrix(const QVector<QVector<double> > & v) {
clear();
if (v.isEmpty()) return;
if (v[0].isEmpty()) return;
blockSignals(true);
int cc = v[0].size();
ui->spinRows->setValue(v.size());
ui->spinCols->setValue(cc);
setVectorMode(false);
for (int r = 0; r < v.size(); ++r) {
for (int c = 0; c < v[r].size(); ++c) {
QTableWidgetItem * i = ui->table->item(r, c);
if (!i) {
i = new QTableWidgetItem();
ui->table->setItem(r, c, i);
}
i->setText(QString::number(v[r][c]));
}
}
blockSignals(false);
emit changed();
}
void MatrixEdit::on_spinRows_valueChanged(int cnt) {
ui->table->setRowCount(cnt);
emit changed();
}
void MatrixEdit::on_spinCols_valueChanged(int cnt) {
ui->table->setColumnCount(cnt);
emit changed();
}
void MatrixEdit::on_buttonNull_clicked() {
clear();
}
void MatrixEdit::on_buttonIdentity_clicked() {
clear(true);
}

View File

@@ -0,0 +1,43 @@
#ifndef MATRIXEDIT_H
#define MATRIXEDIT_H
#include <QWidget>
namespace Ui {
class MatrixEdit;
}
class MatrixEdit: public QWidget {
Q_OBJECT
public:
explicit MatrixEdit(QWidget * parent = 0);
~MatrixEdit();
bool isReadOnly() const;
void setReadOnly(bool yes);
QVector<double> vector() const;
QVector<QVector<double> > matrix() const;
void setVector(const QVector<double> & v);
void setMatrix(const QVector<QVector<double> > & v);
private:
void setVectorMode(bool yes);
void clear(bool ident = false);
Ui::MatrixEdit * ui;
bool ro;
private slots:
void on_spinRows_valueChanged(int cnt);
void on_spinCols_valueChanged(int cnt);
void on_buttonNull_clicked();
void on_buttonIdentity_clicked();
signals:
void changed();
};
#endif // MATRIXEDIT_H

View File

@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MatrixEdit</class>
<widget class="QWidget" name="MatrixEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>283</width>
<height>264</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelCols">
<property name="text">
<string>Cols:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinCols">
<property name="maximum">
<number>65536</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Rows:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinRows">
<property name="maximum">
<number>65536</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonNull">
<property name="toolTip">
<string>Null</string>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonIdentity">
<property name="toolTip">
<string>Identity</string>
</property>
<property name="text">
<string>I</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="table">
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>search(QString)</slot>
<slot>searchNext()</slot>
<slot>searchPrevious()</slot>
<slot>searchAll()</slot>
<slot>hideSearch()</slot>
</slots>
</ui>

View File

@@ -0,0 +1 @@
qad_plugin(widgets "Gui;Widgets" "")

View File

@@ -0,0 +1,69 @@
#include "chardialog.h"
#include "chardialogplugin.h"
#include <QtCore/QtPlugin>
CharDialogPlugin::CharDialogPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void CharDialogPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool CharDialogPlugin::isInitialized() const {
return m_initialized;
}
QWidget * CharDialogPlugin::createWidget(QWidget * parent) {
return new CharDialog(parent);
}
QString CharDialogPlugin::name() const {
return QLatin1String("CharDialog");
}
QString CharDialogPlugin::group() const {
return QLatin1String("Dialogs");
}
QIcon CharDialogPlugin::icon() const {
return QIcon(":/icons/chardialog.png");
}
QString CharDialogPlugin::toolTip() const {
return QLatin1String("Character Select Dialog");
}
QString CharDialogPlugin::whatsThis() const {
return QLatin1String("Character Select Dialog");
}
bool CharDialogPlugin::isContainer() const {
return false;
}
QString CharDialogPlugin::domXml() const {
return QLatin1String("<widget class=\"CharDialog\" name=\"charDialog\">\n</widget>\n");
}
QString CharDialogPlugin::includeFile() const {
return QLatin1String("chardialog.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef CHARDIALOGPLUGIN_H
#define CHARDIALOGPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class CharDialogPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CharDialogPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // CHARDIALOGPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "clineedit.h"
#include "clineeditplugin.h"
#include <QtCore/QtPlugin>
CLineEditPlugin::CLineEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void CLineEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool CLineEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * CLineEditPlugin::createWidget(QWidget * parent) {
return new CLineEdit(parent);
}
QString CLineEditPlugin::name() const {
return QLatin1String("CLineEdit");
}
QString CLineEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon CLineEditPlugin::icon() const {
return QIcon(":/icons/clineedit.png");
}
QString CLineEditPlugin::toolTip() const {
return QLatin1String("Clearable Line Edit");
}
QString CLineEditPlugin::whatsThis() const {
return QLatin1String("Clearable Line Edit");
}
bool CLineEditPlugin::isContainer() const {
return false;
}
QString CLineEditPlugin::domXml() const {
return QLatin1String("<widget class=\"CLineEdit\" name=\"lineEdit\">\n</widget>\n");
}
QString CLineEditPlugin::includeFile() const {
return QLatin1String("clineedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef CLINEEDITPLUGIN_H
#define CLINEEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class CLineEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CLineEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // CLINEEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "colorbutton.h"
#include "colorbuttonplugin.h"
#include <QtCore/QtPlugin>
ColorButtonPlugin::ColorButtonPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void ColorButtonPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool ColorButtonPlugin::isInitialized() const {
return m_initialized;
}
QWidget * ColorButtonPlugin::createWidget(QWidget * parent) {
return new ColorButton(parent);
}
QString ColorButtonPlugin::name() const {
return QLatin1String("ColorButton");
}
QString ColorButtonPlugin::group() const {
return QLatin1String("Buttons");
}
QIcon ColorButtonPlugin::icon() const {
return QIcon(":/icons/colorbutton.png");
}
QString ColorButtonPlugin::toolTip() const {
return QLatin1String("Color Button");
}
QString ColorButtonPlugin::whatsThis() const {
return QLatin1String("Color Button");
}
bool ColorButtonPlugin::isContainer() const {
return false;
}
QString ColorButtonPlugin::domXml() const {
return QLatin1String("<widget class=\"ColorButton\" name=\"colorButton\">\n</widget>\n");
}
QString ColorButtonPlugin::includeFile() const {
return QLatin1String("colorbutton.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef COLORBUTTONPLUGIN_H
#define COLORBUTTONPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class ColorButtonPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ColorButtonPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // COLORBUTTONPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "ecombobox.h"
#include "ecomboboxplugin.h"
#include <QtCore/QtPlugin>
EComboBoxPlugin::EComboBoxPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void EComboBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool EComboBoxPlugin::isInitialized() const {
return m_initialized;
}
QWidget * EComboBoxPlugin::createWidget(QWidget * parent) {
return new EComboBox(parent);
}
QString EComboBoxPlugin::name() const {
return QLatin1String("EComboBox");
}
QString EComboBoxPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon EComboBoxPlugin::icon() const {
return QIcon(":/icons/ecombobox.png");
}
QString EComboBoxPlugin::toolTip() const {
return QLatin1String("Combo Box with Search");
}
QString EComboBoxPlugin::whatsThis() const {
return QLatin1String("Combo Box with Search");
}
bool EComboBoxPlugin::isContainer() const {
return false;
}
QString EComboBoxPlugin::domXml() const {
return QLatin1String("<widget class=\"EComboBox\" name=\"comboBox\">\n</widget>\n");
}
QString EComboBoxPlugin::includeFile() const {
return QLatin1String("ecombobox.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef ECOMBOBOXPLUGIN_H
#define ECOMBOBOXPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class EComboBoxPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
EComboBoxPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // ECOMBOBOXPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "evalspinbox.h"
#include "evalspinboxplugin.h"
#include <QtCore/QtPlugin>
EvalSpinBoxPlugin::EvalSpinBoxPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void EvalSpinBoxPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool EvalSpinBoxPlugin::isInitialized() const {
return m_initialized;
}
QWidget * EvalSpinBoxPlugin::createWidget(QWidget * parent) {
return new EvalSpinBox(parent);
}
QString EvalSpinBoxPlugin::name() const {
return QLatin1String("EvalSpinBox");
}
QString EvalSpinBoxPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon EvalSpinBoxPlugin::icon() const {
return QIcon(":/icons/evalspinbox.png");
}
QString EvalSpinBoxPlugin::toolTip() const {
return QLatin1String("Evaluation double SpinBox");
}
QString EvalSpinBoxPlugin::whatsThis() const {
return QLatin1String("Evaluation double SpinBox");
}
bool EvalSpinBoxPlugin::isContainer() const {
return false;
}
QString EvalSpinBoxPlugin::domXml() const {
return QLatin1String("<widget class=\"EvalSpinBox\" name=\"evalSpin\">\n</widget>\n");
}
QString EvalSpinBoxPlugin::includeFile() const {
return QLatin1String("evalspinbox.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef EVALSPINBOXPLUGIN_H
#define EVALSPINBOXPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class EvalSpinBoxPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
EvalSpinBoxPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // EVALSPINBOXPLUGIN_H

View File

@@ -0,0 +1,36 @@
#ifndef ICONEDLABEPLUGIN_H
#define ICONEDLABEPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class IconedLabelPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
IconedLabelPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // ICONEDLABEPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "image_view.h"
#include "imageviewplugin.h"
#include <QtCore/QtPlugin>
ImageViewPlugin::ImageViewPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void ImageViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool ImageViewPlugin::isInitialized() const {
return m_initialized;
}
QWidget * ImageViewPlugin::createWidget(QWidget * parent) {
return new ImageView(parent);
}
QString ImageViewPlugin::name() const {
return QLatin1String("ImageView");
}
QString ImageViewPlugin::group() const {
return QLatin1String("Display Widgets");
}
QIcon ImageViewPlugin::icon() const {
return QIcon(/*":/icons/spinslider.png"*/);
}
QString ImageViewPlugin::toolTip() const {
return QLatin1String("Image viewer");
}
QString ImageViewPlugin::whatsThis() const {
return QLatin1String("Image viewer");
}
bool ImageViewPlugin::isContainer() const {
return false;
}
QString ImageViewPlugin::domXml() const {
return QLatin1String("<widget class=\"ImageView\" name=\"imageView\">\n</widget>\n");
}
QString ImageViewPlugin::includeFile() const {
return QLatin1String("image_view.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef IMAGEVIEWPLUGIN_H
#define IMAGEVIEWPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class ImageViewPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ImageViewPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif

View File

@@ -0,0 +1,69 @@
#include "iconedlabel.h"
#include "iconedlabelplugin.h"
#include <QtCore/QtPlugin>
IconedLabelPlugin::IconedLabelPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void IconedLabelPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool IconedLabelPlugin::isInitialized() const {
return m_initialized;
}
QWidget * IconedLabelPlugin::createWidget(QWidget * parent) {
return new IconedLabel(parent);
}
QString IconedLabelPlugin::name() const {
return QLatin1String("IconedLabel");
}
QString IconedLabelPlugin::group() const {
return QLatin1String("Display Widgets");
}
QIcon IconedLabelPlugin::icon() const {
return QIcon();
}
QString IconedLabelPlugin::toolTip() const {
return QLatin1String("Label with Icon");
}
QString IconedLabelPlugin::whatsThis() const {
return QLatin1String("Label with Icon");
}
bool IconedLabelPlugin::isContainer() const {
return false;
}
QString IconedLabelPlugin::domXml() const {
return QLatin1String("<widget class=\"IconedLabel\" name=\"iconedLabel\">\n</widget>\n");
}
QString IconedLabelPlugin::includeFile() const {
return QLatin1String("iconedlabel.h");
}

View File

@@ -0,0 +1,47 @@
#include "qad_widgets.h"
#include "spinsliderplugin.h"
#include "colorbuttonplugin.h"
#include "chardialogplugin.h"
#include "shortcutsplugin.h"
#include "clineeditplugin.h"
#include "qipeditplugin.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"
QADWidgets::QADWidgets(QObject * parent): QObject(parent) {
m_widgets.append(new SpinSliderPlugin(this));
m_widgets.append(new ColorButtonPlugin(this));
m_widgets.append(new CharDialogPlugin(this));
m_widgets.append(new ShortcutsPlugin(this));
m_widgets.append(new CLineEditPlugin(this));
m_widgets.append(new QIPEditPlugin(this));
m_widgets.append(new QPointEditPlugin(this));
m_widgets.append(new QRectEditPlugin(this));
m_widgets.append(new EComboBoxPlugin(this));
m_widgets.append(new QPIConsolePlugin(this));
m_widgets.append(new IconedLabelPlugin(this));
m_widgets.append(new QCodeEditPlugin(this));
m_widgets.append(new QVariantEditPlugin(this));
m_widgets.append(new QPIConfigPlugin(this));
m_widgets.append(new EvalSpinBoxPlugin(this));
m_widgets.append(new ImageViewPlugin(this));
}
QList<QDesignerCustomWidgetInterface * > QADWidgets::customWidgets() const {
return m_widgets;
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(qad_widgets_plugin, QADWidgets)
#endif

View File

@@ -0,0 +1,23 @@
#ifndef QAD_WIDGETS_H
#define QAD_WIDGETS_H
#include <QtDesigner/QtDesigner>
#include <QtCore/qplugin.h>
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;
private:
QList<QDesignerCustomWidgetInterface * > m_widgets;
};
#endif // QAD_WIDGETS_H

View File

@@ -0,0 +1,69 @@
#include "qcodeedit.h"
#include "qcodeeditplugin.h"
#include <QtCore/QtPlugin>
QCodeEditPlugin::QCodeEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QCodeEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QCodeEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QCodeEditPlugin::createWidget(QWidget * parent) {
return new QCodeEdit(parent);
}
QString QCodeEditPlugin::name() const {
return QLatin1String("QCodeEdit");
}
QString QCodeEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon QCodeEditPlugin::icon() const {
return QIcon(":/icons/qcodeedit.png");
}
QString QCodeEditPlugin::toolTip() const {
return QLatin1String("QCodeEdit");
}
QString QCodeEditPlugin::whatsThis() const {
return QLatin1String("QCodeEdit");
}
bool QCodeEditPlugin::isContainer() const {
return false;
}
QString QCodeEditPlugin::domXml() const {
return QLatin1String("<widget class=\"QCodeEdit\" name=\"codeEdit\">\n</widget>\n");
}
QString QCodeEditPlugin::includeFile() const {
return QLatin1String("qcodeedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QCODEEDITPLUGIN_H
#define QCODEEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QCodeEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QCodeEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QCODEEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qipedit.h"
#include "qipeditplugin.h"
#include <QtCore/QtPlugin>
QIPEditPlugin::QIPEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QIPEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QIPEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QIPEditPlugin::createWidget(QWidget * parent) {
return new QIPEdit(parent);
}
QString QIPEditPlugin::name() const {
return QLatin1String("QIPEdit");
}
QString QIPEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon QIPEditPlugin::icon() const {
return QIcon();
}
QString QIPEditPlugin::toolTip() const {
return QLatin1String("IP Edit");
}
QString QIPEditPlugin::whatsThis() const {
return QLatin1String("IP Edit");
}
bool QIPEditPlugin::isContainer() const {
return false;
}
QString QIPEditPlugin::domXml() const {
return QLatin1String("<widget class=\"QIPEdit\" name=\"ipEdit\">\n</widget>\n");
}
QString QIPEditPlugin::includeFile() const {
return QLatin1String("qipedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QIPEDITPLUGIN_H
#define QIPEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QIPEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QIPEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QIPEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qpiconfigwidget.h"
#include "qpiconfigplugin.h"
#include <QtCore/QtPlugin>
QPIConfigPlugin::QPIConfigPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QPIConfigPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QPIConfigPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QPIConfigPlugin::createWidget(QWidget * parent) {
return new QPIConfigWidget(parent, 0, false);
}
QString QPIConfigPlugin::name() const {
return QLatin1String("QPIConfigWidget");
}
QString QPIConfigPlugin::group() const {
return QLatin1String("Editor Widgets");
}
QIcon QPIConfigPlugin::icon() const {
return QIcon();
}
QString QPIConfigPlugin::toolTip() const {
return QLatin1String("");
}
QString QPIConfigPlugin::whatsThis() const {
return QLatin1String("");
}
bool QPIConfigPlugin::isContainer() const {
return false;
}
QString QPIConfigPlugin::domXml() const {
return QLatin1String("<widget class=\"QPIConfigWidget\" name=\"piConfigWidget\">\n</widget>\n");
}
QString QPIConfigPlugin::includeFile() const {
return QLatin1String("qpiconfigwidget.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QPICONFIGPLUGIN_H
#define QPICONFIGPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QPIConfigPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QPIConfigPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QPICONFIGPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qpiconsole.h"
#include "qpiconsoleplugin.h"
#include <QtCore/QtPlugin>
QPIConsolePlugin::QPIConsolePlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QPIConsolePlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QPIConsolePlugin::isInitialized() const {
return m_initialized;
}
QWidget * QPIConsolePlugin::createWidget(QWidget * parent) {
return new QPIConsole(parent);
}
QString QPIConsolePlugin::name() const {
return QLatin1String("QPIConsole");
}
QString QPIConsolePlugin::group() const {
return QLatin1String("Display Widgets");
}
QIcon QPIConsolePlugin::icon() const {
return QIcon(":/icons/qpiconsole.png");
}
QString QPIConsolePlugin::toolTip() const {
return QLatin1String("QPIConsole");
}
QString QPIConsolePlugin::whatsThis() const {
return QLatin1String("QPIConsole");
}
bool QPIConsolePlugin::isContainer() const {
return false;
}
QString QPIConsolePlugin::domXml() const {
return QLatin1String("<widget class=\"QPIConsole\" name=\"piConsole\">\n</widget>\n");
}
QString QPIConsolePlugin::includeFile() const {
return QLatin1String("qpiconsole.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QPICONSOLEPLUGIN_H
#define QPICONSOLEPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QPIConsolePlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QPIConsolePlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QPICONSOLEPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qpointedit.h"
#include "qpointeditplugin.h"
#include <QtCore/QtPlugin>
QPointEditPlugin::QPointEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QPointEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QPointEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QPointEditPlugin::createWidget(QWidget * parent) {
return new QPointEdit(parent);
}
QString QPointEditPlugin::name() const {
return QLatin1String("QPointEdit");
}
QString QPointEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon QPointEditPlugin::icon() const {
return QIcon(":/icons/qpointedit.png");
}
QString QPointEditPlugin::toolTip() const {
return QLatin1String("Point Edit");
}
QString QPointEditPlugin::whatsThis() const {
return QLatin1String("Point Edit");
}
bool QPointEditPlugin::isContainer() const {
return false;
}
QString QPointEditPlugin::domXml() const {
return QLatin1String("<widget class=\"QPointEdit\" name=\"pointEdit\">\n</widget>\n");
}
QString QPointEditPlugin::includeFile() const {
return QLatin1String("qpointedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QPOINTEDITPLUGIN_H
#define QPOINTEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QPointEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QPointEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QPOINTEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qrectedit.h"
#include "qrecteditplugin.h"
#include <QtCore/QtPlugin>
QRectEditPlugin::QRectEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QRectEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QRectEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QRectEditPlugin::createWidget(QWidget * parent) {
return new QRectEdit(parent);
}
QString QRectEditPlugin::name() const {
return QLatin1String("QRectEdit");
}
QString QRectEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon QRectEditPlugin::icon() const {
return QIcon(":/icons/qrectedit.png");
}
QString QRectEditPlugin::toolTip() const {
return QLatin1String("Rect Edit");
}
QString QRectEditPlugin::whatsThis() const {
return QLatin1String("Rect Edit");
}
bool QRectEditPlugin::isContainer() const {
return false;
}
QString QRectEditPlugin::domXml() const {
return QLatin1String("<widget class=\"QRectEdit\" name=\"rectEdit\">\n</widget>\n");
}
QString QRectEditPlugin::includeFile() const {
return QLatin1String("qrectedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QRECTEDITPLUGIN_H
#define QRECTEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QRectEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QRectEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QRECTEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "qvariantedit.h"
#include "qvarianteditplugin.h"
#include <QtCore/QtPlugin>
QVariantEditPlugin::QVariantEditPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void QVariantEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QVariantEditPlugin::isInitialized() const {
return m_initialized;
}
QWidget * QVariantEditPlugin::createWidget(QWidget * parent) {
return new QVariantEdit(parent);
}
QString QVariantEditPlugin::name() const {
return QLatin1String("QVariantEdit");
}
QString QVariantEditPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon QVariantEditPlugin::icon() const {
return QIcon(":/icons/qvariantedit.png");
}
QString QVariantEditPlugin::toolTip() const {
return QLatin1String("QVariant Edit");
}
QString QVariantEditPlugin::whatsThis() const {
return QLatin1String("QVariant Edit");
}
bool QVariantEditPlugin::isContainer() const {
return false;
}
QString QVariantEditPlugin::domXml() const {
return QLatin1String("<widget class=\"QVariantEdit\" name=\"variantEdit\">\n</widget>\n");
}
QString QVariantEditPlugin::includeFile() const {
return QLatin1String("qvariantedit.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef QVARIANTEDITPLUGIN_H
#define QVARIANTEDITPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class QVariantEditPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QVariantEditPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // QVARIANTEDITPLUGIN_H

View File

@@ -0,0 +1,69 @@
#include "shortcuts.h"
#include "shortcutsplugin.h"
#include <QtCore/QtPlugin>
ShortcutsPlugin::ShortcutsPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void ShortcutsPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool ShortcutsPlugin::isInitialized() const {
return m_initialized;
}
QWidget * ShortcutsPlugin::createWidget(QWidget * parent) {
return new Shortcuts(parent, false);
}
QString ShortcutsPlugin::name() const {
return QLatin1String("Shortcuts");
}
QString ShortcutsPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon ShortcutsPlugin::icon() const {
return QIcon();
}
QString ShortcutsPlugin::toolTip() const {
return QLatin1String("Shortcuts Edit");
}
QString ShortcutsPlugin::whatsThis() const {
return QLatin1String("Shortcuts Edit");
}
bool ShortcutsPlugin::isContainer() const {
return false;
}
QString ShortcutsPlugin::domXml() const {
return QLatin1String("<widget class=\"Shortcuts\" name=\"shortcuts\">\n</widget>\n");
}
QString ShortcutsPlugin::includeFile() const {
return QLatin1String("shortcuts.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef SHORTCUTSPLUGIN_H
#define SHORTCUTSPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class ShortcutsPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ShortcutsPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif

View File

@@ -0,0 +1,69 @@
#include "spinslider.h"
#include "spinsliderplugin.h"
#include <QtCore/QtPlugin>
SpinSliderPlugin::SpinSliderPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void SpinSliderPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool SpinSliderPlugin::isInitialized() const {
return m_initialized;
}
QWidget * SpinSliderPlugin::createWidget(QWidget * parent) {
return new SpinSlider(parent);
}
QString SpinSliderPlugin::name() const {
return QLatin1String("SpinSlider");
}
QString SpinSliderPlugin::group() const {
return QLatin1String("Input Widgets");
}
QIcon SpinSliderPlugin::icon() const {
return QIcon(":/icons/spinslider.png");
}
QString SpinSliderPlugin::toolTip() const {
return QLatin1String("Spin with Slider");
}
QString SpinSliderPlugin::whatsThis() const {
return QLatin1String("Spin with Slider");
}
bool SpinSliderPlugin::isContainer() const {
return false;
}
QString SpinSliderPlugin::domXml() const {
return QLatin1String("<widget class=\"SpinSlider\" name=\"spinSlider\">\n</widget>\n");
}
QString SpinSliderPlugin::includeFile() const {
return QLatin1String("spinslider.h");
}

View File

@@ -0,0 +1,36 @@
#ifndef SPINSLIDERPLUGIN_H
#define SPINSLIDERPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class SpinSliderPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
SpinSliderPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif

View File

@@ -0,0 +1,72 @@
#include "propertystorage_editor.h"
#include "qvariantedit.h"
#include <QGridLayout>
#include <QToolButton>
PropertyStorageEditor::PropertyStorageEditor(QWidget * parent): QWidget(parent) {
setLayout(new QGridLayout());
layout()->setContentsMargins(0, 0, 0, 0);
storage = 0;
}
PropertyStorageEditor::~PropertyStorageEditor() {
clear();
}
void PropertyStorageEditor::clear() {
qDeleteAll(_widgets);
_widgets.clear();
}
bool PropertyStorageEditor::isEmpty() const {
return ((QGridLayout*)layout())->count() == 0;
}
void PropertyStorageEditor::setStorage(PropertyStorage * s) {
clear();
storage = s;
if (!storage) return;
int r = 0;
QGridLayout * layoutProps = (QGridLayout*)layout();
foreach (const PropertyStorage::Property & p, *storage) {
QLabel * lbl = new QLabel(p.name);
_widgets << lbl;
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
layoutProps->addWidget(lbl, r, 0);
QVariantEdit * ve = new QVariantEdit();
ve->setValue(p.value);
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;
++r;
}
}
void PropertyStorageEditor::applyProperties() {
if (!storage) return;
QList<PropertyStorage::Property> & props(storage->properties());
QGridLayout * layoutProps = (QGridLayout*)layout();
for (int r = 0; r < layoutProps->rowCount(); ++r) {
if (layoutProps->itemAtPosition(r, 0) == 0 || layoutProps->itemAtPosition(r, 1) == 0) continue;
QLabel * lbl = qobject_cast<QLabel * >(layoutProps->itemAtPosition(r, 0)->widget());
QVariantEdit * ve = qobject_cast<QVariantEdit * >(layoutProps->itemAtPosition(r, 1)->widget());
if (lbl == 0 || ve == 0) continue;
QString pn = lbl->text();
for (int i = 0; i < props.size(); ++i) {
PropertyStorage::Property & p(props[i]);
if (p.name == pn) {
p.value = ve->value();
break;
}
}
}
}

View File

@@ -0,0 +1,29 @@
#ifndef PROPERTYSTORAGEEDITOR_H
#define PROPERTYSTORAGEEDITOR_H
#include <QWidget>
#include "propertystorage.h"
class PropertyStorageEditor: public QWidget {
Q_OBJECT
public:
explicit PropertyStorageEditor(QWidget * parent = 0);
~PropertyStorageEditor();
void clear();
bool isEmpty() const;
void setStorage(PropertyStorage * s);
void applyProperties();
private:
QList<QWidget*> _widgets;
PropertyStorage * storage;
signals:
void resetStorageRequest(PropertyStorage * );
void changed();
};
#endif // PROPERTYSTORAGEEDITOR_H

View File

@@ -0,0 +1,46 @@
<RCC>
<qresource prefix="/">
<file>../icons/go-next.png</file>
<file>../icons/go-previous.png</file>
<file>lang/qad_widgets_ru.ts</file>
<file>../icons/dialog-close.png</file>
<file>../icons/edit-clear.png</file>
<file>../icons/edit-guides.png</file>
<file>../icons/view-grid.png</file>
<file>../icons/zoom-fit-best.png</file>
<file>../icons/configure.png</file>
<file>../icons/alpha.png</file>
<file>../icons/document-save.png</file>
<file>../icons/edit-clear-locationbar-rtl.png</file>
<file>../icons/edit-find.png</file>
<file>../icons/list-add.png</file>
<file>../icons/edit-delete.png</file>
<file>../icons/item-add.png</file>
<file>../icons/item.png</file>
<file>../icons/node-add.png</file>
<file>../icons/node.png</file>
<file>../icons/edit-copy.png</file>
<file>../icons/edit-paste.png</file>
<file>../icons/expand_s_x.png</file>
<file>../icons/expand_s_y.png</file>
<file>../icons/expand_x.png</file>
<file>../icons/expand_y.png</file>
<file>../icons/border-line.png</file>
<file>../icons/legend.png</file>
<file>../icons/chardialog.png</file>
<file>../icons/clineedit.png</file>
<file>../icons/colorbutton.png</file>
<file>../icons/ecombobox.png</file>
<file>../icons/qpiconsole.png</file>
<file>../icons/spinslider.png</file>
<file>../icons/etabwidget.png</file>
<file>../icons/qcodeedit.png</file>
<file>../icons/qvariantedit.png</file>
<file>../icons/code-word.png</file>
<file>../icons/f1.png</file>
<file>../icons/dialog-ok-apply.png</file>
<file>../icons/dialog-warning.png</file>
<file>../icons/tools-wizard.png</file>
<file>../icons/evalspinbox.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,1443 @@
#include "qcodeedit.h"
#include <QLayout>
#include <QBoxLayout>
#include <QScrollBar>
#include <QTextDocument>
#include <QTextDocumentFragment>
#include <QTextOption>
#include <QTextCursor>
#include <QTextBlock>
#include <QAction>
#include <QApplication>
#include <QHeaderView>
#include "ecombobox.h"
#include "qad_types.h"
#include "ui_qcodeedit.h"
Q_DECLARE_METATYPE(QTextCursor)
QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) {
qRegisterMetaType<QTextCursor>();
ui = new Ui::QCodeEdit();
ui->setupUi(this);
ui->widgetSearch->hide();
ui->comboSearch->installEventFilter(this);
ui->comboReplace->installEventFilter(this);
prev_lc = auto_comp_pl = cur_search_ind = pos_press = pos_el_press = -1;
timer = 0;
_ignore_focus_out = _destructor = _replacing = false;
_first = true;
es_line.format.setBackground(QColor(240, 245, 240));
es_line.format.setProperty(QTextFormat::FullWidthSelection, true);
es_cursor.format.setBackground(QColor(220, 255, 200));
es_bracket.format.setBackground(QColor(180, 238, 180));
es_bracket.format.setForeground(Qt::red);
es_search.format.setBackground(QColor(255, 240, 10));
es_range.format.setBackground(QColor(230, 246, 255));
es_range.format.setProperty(QTextFormat::FullWidthSelection, true);
widget_help = new QFrame();
widget_help->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
widget_help->setFocusPolicy(Qt::NoFocus);
widget_help->setFrameShadow(QFrame::Sunken);
widget_help->setFrameShape(QFrame::StyledPanel);
widget_help->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
widget_help->layout()->setContentsMargins(0, 0, 0, 0);
for (int i = 0; i < 2; ++i) {
lbl_help[i] = new IconedLabel();
lbl_help[i]->setFrameShadow(QFrame::Plain);
lbl_help[i]->setFrameShape(QFrame::NoFrame);
lbl_help[i]->setDirection(IconedLabel::RightToLeft);
widget_help->layout()->addWidget(lbl_help[i]);
}
lbl_help[1]->setIcon(QIcon(":/icons/f1.png"));
lbl_help[1]->setText(trUtf8("Press F1 for details"));
completer = new QTreeWidget();
completer->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
completer->setFocusPolicy(Qt::NoFocus);
completer->setColumnCount(2);
completer->setRootIsDecorated(false);
completer->setHeaderHidden(true);
completer->header()->setDefaultAlignment(Qt::AlignCenter);
completer->header()->
#if (QT_VERSION >= 0x050000)
setSectionResizeMode
#else
setResizeMode
#endif
(QHeaderView::ResizeToContents);
completer->header()->setStretchLastSection(true);
ui->textCode->setCursorWidth(qMax<int>(qRound(fontHeight() / 10.), 1));
ui->textLines->viewport()->setAutoFillBackground(false);
ui->textLines->viewport()->setCursor(Qt::ArrowCursor);
ui->textLines->setFixedWidth(ui->textLines->fontMetrics().width(" "));
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->setShortcut(QKeySequence("Ctrl+D"));
a->setShortcutContext(Qt::WidgetShortcut);
connect(a, SIGNAL(triggered()), this, SLOT(deleteLine()));
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->setShortcut(QKeySequence("Ctrl+Up"));
a->setShortcutContext(Qt::WidgetShortcut);
connect(a, SIGNAL(triggered()), this, SLOT(scrollUp()));
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->setShortcut(QKeySequence("Ctrl+Shift+Return"));
a->setShortcutContext(Qt::WidgetShortcut);
connect(a, SIGNAL(triggered()), this, SLOT(newLineBefore()));
ui->frame->setFocusProxy(ui->textCode);
QTextOption to = ui->textLines->document()->defaultTextOption();
to.setAlignment(Qt::AlignTop | Qt::AlignRight);
ui->textLines->document()->setDefaultTextOption(to);
/*to = ui->textCode->document()->defaultTextOption();
to.setFlags(QTextOption::SuppressColors);
ui->textCode->document()->setDefaultTextOption(to);*/
setShowSpaces(true);
a = new QAction(this);
a->setShortcut(QKeySequence("Ctrl+F"));
a->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(a, SIGNAL(triggered(bool)), this, SLOT(search_triggered()));
addAction(a);
/*a = new QAction(this);
a->setShortcut(QKeySequence("Esc"));
a->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(a, SIGNAL(triggered(bool)), this, SLOT(hideSearch()));
addAction(a);*/
connect(completer, SIGNAL(itemDoubleClicked(QTreeWidgetItem * ,int)), this, SLOT(commitCompletition()));
connect(ui->textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), ui->textLines->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideHelp()));
connect(ui->textCode, SIGNAL(textChanged()), this, SLOT(textEdit_textChanged()));
connect(ui->textCode, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
connect(ui->textCode, SIGNAL(cursorPositionChanged()), this, SLOT(textEdit_cursorPositionChanged()));
connect(ui->textCode, SIGNAL(selectionChanged()), this, SLOT(textEdit_selectionChanged()));
connect(ui->comboSearch->lineEdit(), SIGNAL(returnPressed()), this, SLOT(searchNext()));
connect(ui->comboReplace->lineEdit(), SIGNAL(returnPressed()), this, SLOT(on_buttonReplaceSearch_clicked()));
updateLines();
registerAutoCompletitionClass(-1, QCodeEdit::Keyword, "Words", QIcon(":/icons/code-word.png"));
}
QCodeEdit::~QCodeEdit() {
_destructor = true;
delete completer;
//for (int i = 0; i < 2; ++i)
// delete lbl_help[i];
delete widget_help;
//delete ui;
}
QTextCursor QCodeEdit::textCursor() const {
return ui->textCode->textCursor();
}
QTextDocument * QCodeEdit::document() const {
return ui->textCode->document();
}
void QCodeEdit::setDocument(QTextDocument * doc) {
if (document()) {
document()->setProperty("_cursor", QVariant::fromValue(textCursor()));
document()->setProperty("_vpos", textEdit()->verticalScrollBar()->value());
}
ui->textCode->setEnabled(doc);
ui->textLines->setEnabled(doc);
documentUnset();
if (!doc) {
ui->textCode->setDocument(0);
documentChanged(0);
return;
}
if (!qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()))
doc->setDocumentLayout(new QPlainTextDocumentLayout(doc));
ui->textCode->setDocument(doc);
ui->textCode->setCursorWidth(qMax<int>(qRound(fontHeight() / 10.), 1));
setShowSpaces(spaces_);
if (doc->property("_cursor").isValid()) {
setTextCursor(doc->property("_cursor").value<QTextCursor>());
textEdit()->verticalScrollBar()->setValue(doc->property("_vpos").toInt());
}
documentChanged(doc);
doc->setDefaultFont(editorFont());
updateLines();
}
void QCodeEdit::setTextCursor(const QTextCursor & c) {
ui->textCode->setTextCursor(c);
}
void QCodeEdit::centerCursor() {
ui->textCode->centerCursor();
updateLines();
}
void QCodeEdit::insertText(const QString & text) {
ui->textCode->insertPlainText(text);
updateLines();
}
void QCodeEdit::appendText(const QString & text) {
ui->textCode->appendPlainText(text);
updateLines();
}
void QCodeEdit::setCustomExtraSelection(const QList<QTextEdit::ExtraSelection> & es) {
es_custom = es;
applyExtraSelection();
}
QRect QCodeEdit::cursorRect() const {
return ui->textCode->cursorRect();
}
QRect QCodeEdit::cursorRect(const QTextCursor & cursor) const {
return ui->textCode->cursorRect(cursor);
}
QString QCodeEdit::text() const {
return ui->textCode->toPlainText();
}
QStringList QCodeEdit::cursorScope() const {
return cursor_scope;
}
bool QCodeEdit::showLineNumbers() const {
return ui->textLines->isVisible();
}
void QCodeEdit::setEditorFont(QFont f) {
ui->textCode->setFont(f);
ui->textLines->setFont(f);
}
QFont QCodeEdit::editorFont() const {
return ui->textCode->font();
}
QPlainTextEdit * QCodeEdit::textEdit() const {
return ui->textCode;
}
int QCodeEdit::skipRange(const QString & s, int pos, QChar oc, QChar cc, QChar sc) {
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;}
}
return -1;
}
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];
if (c.isLetterOrNumber() || (c.toLatin1() == '_')) continue;
if (pc.isLetter() || (pc.toLatin1() == '_')) return i + 1;
return -1;
}
return -1;
}
bool QCodeEdit::matchWritten(QString s, QString w) {
if (s.isEmpty() || w.isEmpty()) return true;
if (s.contains(w, Qt::CaseInsensitive)) return true;
int sp(0);
for (int i = 0; i < w.size(); ++i, ++sp) {
if (sp >= s.size()) return false;
QChar wc(w[i].toLower());
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].toLower() != wc) return false;
}
if (s[sp].toLower() == wc) break;
ns = true;
sp++;
}
if (sp >= s.size()) return false;
}
return true;
}
QChar QCodeEdit::pairChar(QChar c) {
switch (c.toLatin1()) {
case '\"': return '\"';
case '(': return ')';
case ')': return '(';
case '[': return ']';
case ']': return '[';
default: break;
}
return QChar();
}
bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
if (_destructor) return QWidget::eventFilter(o, e);
if (e->type() == QEvent::Destroy) {
completer->removeEventFilter(this);
ui->textCode->removeEventFilter(this);
ui->textCode->viewport()->removeEventFilter(this);
ui->textLines->viewport()->removeEventFilter(this);
return QWidget::eventFilter(o, e);
}
if (ui->textLines) {
if (o == ui->textLines->viewport()) {/*
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease ||
e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonDblClick) {
#if (QT_VERSION < 0x050000)
const_cast<QPoint&>(((QMouseEvent*)e)->pos()) = QPoint(0, ((QMouseEvent*)e)->pos().y());
#else
const_cast<QPointF&>(((QMouseEvent*)e)->localPos()) = QPointF(0, ((QMouseEvent*)e)->localPos().y());
#endif
QApplication::sendEvent(ui->textCode->viewport(), e);
return true;
}*/
QTextCursor tc;
int tcpos = 0;
switch (e->type()) {
case QEvent::MouseButtonPress:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::EndOfLine);
pos_el_press = tc.anchor();
tc.movePosition(QTextCursor::StartOfLine);
pos_press = tc.anchor();
if (!tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor))
tc.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
ui->textCode->setTextCursor(tc);
return true;
case QEvent::MouseMove:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::StartOfLine);
if (pos_press == tc.anchor()) {
if (!tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor))
tc.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
ui->textCode->setTextCursor(tc);
return true;
}
if (pos_press < tc.anchor()) {
if (!tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor))
tc.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
}
tcpos = tc.position();
tc.setPosition(pos_press < tc.anchor() ? pos_press : pos_el_press);
tc.setPosition(tcpos, QTextCursor::KeepAnchor);
ui->textCode->setTextCursor(tc);
return true;
case QEvent::Wheel:
if (!isEnabled()) break;
QApplication::sendEvent(ui->textCode->viewport(), e);
return true;
default: break;
}
}
}
if (o == completer) {
//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;
if (e->type() == QEvent::KeyPress) {
if (((QKeyEvent * )e)->key() == Qt::Key_Escape) {
hideHelp();
if (completer->isVisible())
completer->hide();
else
hideSearch();
}
}
//qDebug() << e;
return QWidget::eventFilter(o, e);
}
if (ui->textCode) {
if (o == ui->textCode->viewport()) {
if (e->type() == QEvent::MouseButtonPress) {
completer->hide();
hideHelp();
}
return QWidget::eventFilter(o, e);
}
if (o == ui->textCode) {
//qDebug() << e;
QMetaObject::invokeMethod(this, "syncScrolls", Qt::QueuedConnection);
QKeyEvent * ke;
QChar kc(0);
switch (e->type()) {
case QEvent::ToolTip: {
QTextCursor tc = ui->textCode->cursorForPosition(((QHelpEvent*)e)->pos());
tc.select(QTextCursor::WordUnderCursor);
raiseHelp(tc);
}
break;
case QEvent::KeyPress:
ke = (QKeyEvent * )e;
//qDebug() << "key" << ke;
switch (ke->key()) {
case Qt::Key_Space:
if (ke->modifiers().testFlag(Qt::ControlModifier)) {
invokeAutoCompletition(true);
return true;
}
break;
case Qt::Key_Escape:
hideHelp();
if (completer->isVisible())
completer->hide();
else
hideSearch();
break;
case Qt::Key_Up:
if (completer->isVisible()) {
previousCompletition();
return true;
}
completer->hide();
hideHelp();
if (ke->modifiers().testFlag(Qt::AltModifier)) {
copyLineUp();
return true;
}
if (ke->modifiers().testFlag(Qt::ControlModifier) && ke->modifiers().testFlag(Qt::ShiftModifier)) {
moveLineUp();
return true;
}
break;
case Qt::Key_Down:
if (completer->isVisible()) {
nextCompletition();
return true;
}
completer->hide();
hideHelp();
if (ke->modifiers().testFlag(Qt::AltModifier)) {
copyLineDown();
return true;
}
if (ke->modifiers().testFlag(Qt::ControlModifier) && ke->modifiers().testFlag(Qt::ShiftModifier)) {
moveLineDown();
return true;
}
break;
case Qt::Key_Home:
case Qt::Key_End:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
if (completer->isVisible()) {
qApp->sendEvent(completer, new QKeyEvent(e->type(), ke->key(), ke->modifiers()));
return true;
}
break;
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Backspace:
case Qt::Key_Delete:
if (completer->isVisible())
QMetaObject::invokeMethod(this, "invokeAutoCompletition", Qt::QueuedConnection, Q_ARG(bool, false));
break;
case Qt::Key_Return:
if (completer->isVisible()) {
commitCompletition();
completer->hide();
return true;
}
if (ui->textCode->textCursor().selectedText().isEmpty())
QMetaObject::invokeMethod(this, "autoIndent", Qt::QueuedConnection);
break;
case Qt::Key_Tab:
if (!ui->textCode->textCursor().selectedText().isEmpty()) {
if (ke->modifiers().testFlag(Qt::ShiftModifier))
deindent();
else
indent();
return true;
}
break;
case Qt::Key_D:
if (ke->modifiers().testFlag(Qt::ControlModifier)) {
completer->hide();
return true;
}
break;
default: break;
}
if (!ke->text().isEmpty())
kc = ke->text()[0];
if (kc == '.') {
completer->hide();
QMetaObject::invokeMethod(this, "invokeAutoCompletition", Qt::QueuedConnection, Q_ARG(bool, false));
} else {
if ((kc.isLetterOrNumber() || kc.toLatin1() == '_') && completer->isVisible())
QMetaObject::invokeMethod(this, "invokeAutoCompletition", Qt::QueuedConnection, Q_ARG(bool, false));
}
break;
case QEvent::FocusOut:
if (_ignore_focus_out) {
_ignore_focus_out = false;
break;
}
case QEvent::Hide:
case QEvent::HideToParent:
case QEvent::MouseButtonPress:
//qDebug() << e;
completer->hide();
hideHelp();
default: break;
}
}
}
return QWidget::eventFilter(o, e);
}
void QCodeEdit::showEvent(QShowEvent * ) {
if (!_first) return;
_first = false;
completer->installEventFilter(this);
ui->textCode->installEventFilter(this);
ui->textCode->viewport()->installEventFilter(this);
ui->textLines->viewport()->installEventFilter(this);
}
void QCodeEdit::timerEvent(QTimerEvent * ) {
parse();
emit parseRequest();
killTimer(timer);
timer = 0;
}
void QCodeEdit::leaveEvent(QEvent * e) {
hideHelp();
QWidget::leaveEvent(e);
}
char antiBracket(char c) {
switch (c) {
case '(': return ')';
case '[': return ']';
case '{': return '}';
case '<': return '>';
case ')': return '(';
case ']': return '[';
case '}': return '{';
case '>': return '<';
}
return 0;
}
void QCodeEdit::highlightBrackets() {
es_brackets.clear();
QTextCursor stc = ui->textCode->textCursor(), tc;
QTextEdit::ExtraSelection es;
stc.setPosition(stc.position());
QTextCursor::MoveOperation mop[2] = {QTextCursor::Left, QTextCursor::Right};
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.cursor = tc;
es_brackets << es;
QTextCursor ftc = tc;
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();
if (ftc.selectedText().isEmpty()) break;
if (ftc.selectedText()[0].toLatin1() == ch) ++bcnt;
if (ftc.selectedText()[0].toLatin1() == fch) --bcnt;
}
if (bcnt == 0) {
es.cursor = ftc;
es_brackets << es;
es.format = es_range.format;
es.cursor.setPosition(tc.position(), QTextCursor::KeepAnchor);
if (!es.cursor.selection().isEmpty())
es_brackets << es;
}
}
}
}
}
void QCodeEdit::applyExtraSelection() {
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected
<< es_custom << es_brackets << es_search_list << es_cursor);
}
void QCodeEdit::nextCompletition() {
int ci = completer->currentIndex().row();
if (ci >= completer->topLevelItemCount() - 1) return;
if (completer->topLevelItem(ci + 1)->flags().testFlag(Qt::ItemIsSelectable))
completer->setCurrentItem(completer->topLevelItem(ci + 1));
else {
if (ci >= completer->topLevelItemCount() - 2) return;
completer->setCurrentItem(completer->topLevelItem(ci + 2));
}
}
void QCodeEdit::previousCompletition() {
int ci = completer->currentIndex().row();
if (ci <= 0) return;
if (completer->topLevelItem(ci - 1)->flags().testFlag(Qt::ItemIsSelectable))
completer->setCurrentItem(completer->topLevelItem(ci - 1));
else {
if (ci <= 1) return;
completer->setCurrentItem(completer->topLevelItem(ci - 2));
}
}
void QCodeEdit::clearSearch() {
es_search_list.clear();
applyExtraSelection();
}
void QCodeEdit::moveToSearch() {
if (es_search_list.isEmpty()) return;
if (cur_search_ind < 0) cur_search_ind += es_search_list.size();
if (cur_search_ind >= es_search_list.size()) cur_search_ind = 0;
if (cur_search_ind < 0 || cur_search_ind >= es_search_list.size()) return;
ui->textCode->setTextCursor(es_search_list[cur_search_ind].cursor);
}
int QCodeEdit::searchIndFromCursor() {
if (es_search_list.isEmpty()) return -1;
int ci = ui->textCode->textCursor().anchor();
for (int i = 0; i < es_search_list.size(); ++i)
if (es_search_list[i].cursor.anchor() > ci)
return i - 1;
return -1;
}
void QCodeEdit::searchAll() {
QString st = ui->comboSearch->currentText();
es_search_list.clear();
if (!st.isEmpty() && !ui->widgetSearch->isHidden()) {
QTextDocument::FindFlags ff = 0;
if (ui->buttonSearchCase->isChecked()) ff |= QTextDocument::FindCaseSensitively;
if (ui->buttonSearchWord->isChecked()) ff |= QTextDocument::FindWholeWords;
QTextCursor tc(ui->textCode->document()->begin());
QTextEdit::ExtraSelection es = es_search;
while (true) {
tc = ui->textCode->document()->find(st, tc, ff);
if (tc.isNull()) break;
es.cursor = tc;
es_search_list << es;
}
}
applyExtraSelection();
QString ss;
if (es_search_list.isEmpty())
ss = "color: rgb(180, 0, 0);";
ui->comboSearch->lineEdit()->setStyleSheet(ss);
}
void QCodeEdit::search_triggered() {
QTextCursor tc = ui->textCode->textCursor();
QString st = tc.selectedText();
if (st.isEmpty()) {
tc.select(QTextCursor::WordUnderCursor);
st = tc.selectedText();
}
search(st);
//QMetaObject::invokeMethod(ui->comboSearch->lineEdit(), "returnPressed");
if (ui->comboSearch->findText(st) < 0)
ui->comboSearch->insertItem(0, st);
}
void QCodeEdit::syncScrolls() {
ui->textLines->verticalScrollBar()->setValue(ui->textCode->verticalScrollBar()->value());
ui->textLines->setHorizontalScrollBarPolicy(ui->textCode->horizontalScrollBar()->isVisible() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff);
//qDebug() << "!!!";
}
void QCodeEdit::scrollUp() {
ui->textCode->verticalScrollBar()->setValue(ui->textCode->verticalScrollBar()->value() - 1);
}
void QCodeEdit::scrollDown() {
ui->textCode->verticalScrollBar()->setValue(ui->textCode->verticalScrollBar()->value() + 1);
}
void QCodeEdit::deleteLine() {
QTextCursor tc = ui->textCode->textCursor();
tc.movePosition(QTextCursor::EndOfLine);
tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
bool md = true;
if (!tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor)) {
tc.movePosition(QTextCursor::StartOfLine);
tc.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
md = false;
}
tc.removeSelectedText();
tc.movePosition(QTextCursor::StartOfLine);
if (md) tc.movePosition(QTextCursor::Down);
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::copyLineUp() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(ss); tc.setPosition(se, QTextCursor::KeepAnchor);
bool ins_nl = false;
if (!tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor))
ins_nl = true;
QString l = tc.selectedText();
tc.beginEditBlock();
tc.setPosition(ss);
if (ins_nl)
l.append("\n");
tc.insertText(l);
tc.setPosition(ss_);
tc.setPosition(se_, QTextCursor::KeepAnchor);
tc.endEditBlock();
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::copyLineDown() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(ss); tc.setPosition(se, QTextCursor::KeepAnchor);
bool ins_nl = false;
if (!tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor))
ins_nl = true;
QString l = tc.selectedText();
tc.beginEditBlock();
tc.setPosition(ss);
ss_ += l.size(); se_ += l.size();
if (ins_nl) {
l.append("\n");
ss_++; se_++;
}
tc.insertText(l);
tc.setPosition(ss_);
tc.setPosition(se_, QTextCursor::KeepAnchor);
tc.endEditBlock();
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::moveLineUp() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(ss);
if (!tc.movePosition(QTextCursor::Up))
return;
tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
QString l = tc.selectedText();
ss -= l.size(); se -= l.size();
ss_ -= l.size(); se_ -= l.size();
tc.beginEditBlock();
tc.removeSelectedText();
tc.setPosition(se);
bool de = false;
if (!tc.movePosition(QTextCursor::Right)) {
l.prepend("\n");
de = true;
}
tc.insertText(l);
if (de) {
tc.movePosition(QTextCursor::End);
tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
tc.removeSelectedText();
}
tc.setPosition(ss_);
tc.setPosition(se_, QTextCursor::KeepAnchor);
tc.endEditBlock();
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::moveLineDown() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(se);
if (!tc.movePosition(QTextCursor::Right))
return;
bool de = false;
if (!tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor)) {
tc.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
de = true;
}
QString l = tc.selectedText();
tc.beginEditBlock();
tc.removeSelectedText();
tc.setPosition(ss);
if (de) l += "\n";
tc.insertText(l);
if (de) {
tc.movePosition(QTextCursor::End);
tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
tc.removeSelectedText();
}
ss += l.size(); se += l.size();
ss_ += l.size(); se_ += l.size();
tc.setPosition(ss_);
tc.setPosition(se_, QTextCursor::KeepAnchor);
tc.endEditBlock();
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::indent() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(ss);
while (tc.position() < se_) {
tc.insertText("\t");
se_++;
tc.movePosition(QTextCursor::StartOfLine);
if (!tc.movePosition(QTextCursor::Down))
break;
}
tc.setPosition(ss_ + 1);
tc.setPosition(se_, QTextCursor::KeepAnchor);
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::deindent() {
QTextCursor tc = ui->textCode->textCursor();
int ss = tc.selectionStart(), ss_ = ss, se = tc.selectionEnd(), se_ = se;
QString st_ = tc.selection().toPlainText();
if (st_.endsWith("\n")) {
st_.chop(1);
se--; se_--;
}
tc.setPosition(ss); tc.movePosition(QTextCursor::StartOfLine); ss = tc.position();
tc.setPosition(se); tc.movePosition(QTextCursor::EndOfLine); se = tc.position();
tc.setPosition(ss);
bool first = true;
while (tc.position() < se_) {
tc.movePosition(QTextCursor::StartOfLine);
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
int rs = 0;
if (tc.selectedText() == "\t") {
tc.removeSelectedText();
rs = 1;
} else {
for (int i = 0; i < 4; ++i) {
tc.movePosition(QTextCursor::StartOfLine);
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
if (tc.selectedText() == " ") {
tc.removeSelectedText();
rs++;
}
}
}
if (first) {
first = false;
ss_ -= rs;
}
se_ -= rs;
tc.movePosition(QTextCursor::StartOfLine);
if (!tc.movePosition(QTextCursor::Down))
break;
}
tc.setPosition(ss_);
tc.setPosition(se_, QTextCursor::KeepAnchor);
ui->textCode->setTextCursor(tc);
}
void QCodeEdit::autoIndent() {
QTextCursor tc = ui->textCode->textCursor(), stc = tc;
tc.movePosition(QTextCursor::StartOfLine);
if (!tc.movePosition(QTextCursor::Up)) return;
tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
QString line = tc.selectedText(), tabs;
int i = 0;
for (; i < line.size(); ++i)
if (!line[i].isSpace()) {
tabs = line.left(i);
break;
}
if (i >= line.size())
tabs = line.left(line.size() - 1);
int nt = qMax<int>(0, line.count(QChar('{')) - line.count(QChar('}')));
tabs.append(QString("\t").repeated(nt));
if (tabs.isEmpty()) return;
stc.insertText(tabs);
ui->textCode->setTextCursor(stc);
}
void QCodeEdit::scrollToTop() {
prev_lc = -1;
updateLines();
ui->textCode->verticalScrollBar()->setValue(0);
ui->textLines->verticalScrollBar()->setValue(0);
}
void QCodeEdit::newLine() {
QTextCursor tc = ui->textCode->textCursor();
tc.movePosition(QTextCursor::EndOfLine);
tc.insertText("\n");
ui->textCode->setTextCursor(tc);
QMetaObject::invokeMethod(this, "autoIndent", Qt::QueuedConnection);
}
void QCodeEdit::newLineBefore() {
QTextCursor tc = ui->textCode->textCursor();
tc.movePosition(QTextCursor::StartOfLine);
tc.insertText("\n");
tc.movePosition(QTextCursor::Up);
ui->textCode->setTextCursor(tc);
QMetaObject::invokeMethod(this, "autoIndent", Qt::QueuedConnection);
}
void QCodeEdit::setFocus() {
ui->textCode->setFocus();
}
void QCodeEdit::setText(const QString & t) {
ui->textCode->setPlainText(t);
}
void QCodeEdit::updateLines() {
if (timer > 0) killTimer(timer);
timer = startTimer(500);
ui->textCode->setTabStopWidth(ui->textCode->fontMetrics().width(" "));
int lc = ui->textCode->document()->lineCount();
if (prev_lc == lc) return;
prev_lc = lc;
ui->textLines->setFixedWidth(ui->textLines->fontMetrics().width(QString(" %1").arg(lc)));
ui->textLines->clear();
for (int i = 1; i <= lc; ++i)
ui->textLines->appendPlainText(QString("%1").arg(i));
ui->textLines->verticalScrollBar()->setValue(ui->textCode->verticalScrollBar()->value());
}
QString QCodeEdit::selectArg(QString s, int arg) {
if (!s.contains('(') || arg < 0) return s;
QString ss = s.left(s.indexOf('('));
s.remove(0, ss.size());
if (s.startsWith('(')) s.remove(0, 1);
if (s.endsWith(')')) s.chop(1);
QStringList al = s.split(",");
QString ret = ss + "(";
for (int i = 0; i < al.size(); ++i) {
if (i > 0) ret += ", ";
if (i == arg) ret += "<span style=\"font-weight:600;\">";
ret += al[i].trimmed();
if (i == arg) ret += "</span>";
}
ret += ")";
return ret;
}
void QCodeEdit::raiseHelp(QTextCursor tc, int arg) {
bool ok;
QPair<QStringList, QString> scope = getScope(tc, &ok);
QString st = tc.selectedText();
if (arg >= 0) st = scope.second;
if (!ok || st.isEmpty()) {
hideHelp();
return;
}
ok = false;
ACList acl(autoCompletitionList(scope.first, scope.second));
foreach (const ACPair & i, acl) {
foreach (const StringsPair & s, i.second) {
QString ts = s.second;
//qDebug() << ts << st;
if (ts != st) {
if (ts.startsWith(st)) {
ts.remove(0, st.size());
ts = ts.trimmed();
if (!ts.isEmpty()) {
if (ts[0] != '(')
continue;
}
} else
continue;
}
//qDebug() << s.second << st;
ACClass acc = ac_classes.value(i.first);
lbl_help[0]->setIcon(acc.icon);
lbl_help[0]->setText(QString("<html><body>[%1] %2 %3</html></body>").arg(acc.name, s.first, selectArg(s.second, arg)));
ok = true;
break;
}
if (ok) break;
}
if (!ok) {
hideHelp();
return;
}
//qDebug() << "help found" << tc.selectionStart() << tc.selectionEnd();
es_cursor.cursor = tc;
applyExtraSelection();
//tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
lbl_help[0]->setFont(font());
qApp->processEvents();
widget_help->resize(widget_help->sizeHint());
qApp->processEvents();
QRect whr = ui->textCode->cursorRect(tc);
whr.setWidth(ui->textCode->fontMetrics().width(st));
QPoint whp;
whp.setX(whr.left() - whr.width() - (widget_help->width() - whr.width()) / 2);
whp.setY(whr.top() - widget_help->height() - (fontHeight() / 3));
//qDebug() << whr << whp << widget_help->width() << ", " << st;
widget_help->move(ui->textCode->viewport()->mapToGlobal(whp));
widget_help->show();
widget_help->raise();
cursor_scope = scope.first;
cursor_scope << scope.second;
//qDebug() << "tooltip" << st;
}
void QCodeEdit::hideHelp() {
widget_help->hide();
es_cursor.cursor = QTextCursor();
cursor_scope.clear();
applyExtraSelection();
}
QTextCursor QCodeEdit::functionStart(QTextCursor tc, int * arg) {
QString doc = ui->textCode->toPlainText();
int bcnt = 0, a = 0, i = -1;
for (i = tc.position() - 1; i >= 0; --i) {
if (doc[i] == ')') bcnt++;
if (doc[i] == '(') {
if (bcnt == 0)
break;
else
bcnt--;
}
//if (doc[i] == '(') bcnt--;
if (doc[i] == ',' && bcnt == 0) a++;
}
if (i < 0) return QTextCursor();
if (arg) *arg = a;
QTextCursor ret(ui->textCode->document());
ret.setPosition(i);
//qDebug() << "found" << i << a;
return ret;
}
QCodeEdit::ACList QCodeEdit::wordsCompletitionList(const QString & written) const {
QCodeEdit::ACList ret;
if (!written.isEmpty()) {
QTextCursor tc = QTextCursor(ui->textCode->document()->begin()), stc;
QStringList acwl;
tc = QTextCursor(ui->textCode->document()->begin());
while (true) {
tc = ui->textCode->document()->find(written, tc);
if (tc.isNull()) break;
stc = tc;
stc.movePosition(QTextCursor::Left);
stc.select(QTextCursor::WordUnderCursor);
if (!stc.selectedText().isEmpty() && stc.selectedText().trimmed() != written)
acwl << stc.selectedText();
}
acwl.removeDuplicates();
ACPair acl;
acl.first = -1;
foreach (const QString & s, acwl)
acl.second << StringsPair("", s);
ret << acl;
}
return ret;
}
QPair<QStringList, QString> QCodeEdit::getScope(QTextCursor tc, bool * ok) {
QPair<QStringList, QString> ret;
QTextCursor stc = tc;
if (tc.isNull()) {
completer->hide();
if (ok) *ok = false;
return ret;
}
int line = tc.block().firstLineNumber();
if (completer->isVisible()) {
if (auto_comp_pl != line) {
completer->hide();
auto_comp_pl = line;
if (ok) *ok = false;
return ret;
}
}
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 ***";
if (written != "_" && !written.leftJustified(1)[0].isLetterOrNumber()) {
written.clear();
} else {
cpos = skipCWord(doc, spos);
if (cpos >= 0)
written = doc.mid(cpos, spos - cpos).trimmed();
}
while (cpos >= 0) {
cpos--;
//qDebug() << "char =" << doc.mid(cpos, 1);
if (doc.mid(cpos, 1) != ".") break;
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;
if (cpos < 0) break;
}
int npos = skipCWord(doc, cpos);
if (npos < 0) break;
scope.push_front(doc.mid(npos, ppos - npos));
cpos = npos;
}
ret.first = scope;
ret.second = written;
if (ok) *ok = true;
return ret;
}
void QCodeEdit::invokeAutoCompletition(bool force) {
int arg = -1;
QTextCursor htc = functionStart(ui->textCode->textCursor(), &arg);
if (!htc.isNull()) {
//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();
if (scope.first.isEmpty() && scope.second.isEmpty() && !force) {
completer->hide();
hideHelp();
return;
}
acl << wordsCompletitionList(scope.second);
QFont bf(font());
bf.setBold(true);
foreach (const ACPair & ac, acl) {
if (ac.second.isEmpty()) continue;
ACClass acc = ac_classes.value(ac.first);
QTreeWidgetItem * gi = new QTreeWidgetItem();
gi->setText(0, acc.name);
gi->setTextAlignment(0, Qt::AlignCenter);
gi->setTextAlignment(1, Qt::AlignCenter);
gi->setFont(0, bf);
gi->setBackgroundColor(0, Qt::lightGray);
gi->setFlags(Qt::ItemIsEnabled);
completer->addTopLevelItem(gi);
gi->setFirstColumnSpanned(true);
foreach (const StringsPair & s, ac.second) {
QTreeWidgetItem * ni = new QTreeWidgetItem();
ni->setIcon(0, acc.icon);
ni->setText(0, s.first);
ni->setText(1, s.second);
completer->addTopLevelItem(ni);
}
}
if (completer->topLevelItemCount() > 1)
completer->setCurrentItem(completer->topLevelItem(1));
if (completer->isHidden())
completer->move(ui->textCode->mapToGlobal(ui->textCode->cursorRect().bottomRight()));
if (completer->topLevelItemCount() > 0) {
completer->setVisible(true);
//qApp->processEvents();
int sz = completer->verticalScrollBar()->width();
for (int i = 0; i < completer->header()->count(); ++i)
sz += qMax<int>(sz, ((QAbstractItemView*)completer)->sizeHintForColumn(i));
completer->resize(sz, fontHeight() * 16);
} else
completer->hide();
}
void QCodeEdit::commitCompletition() {
if (completer->currentItem() == 0) return;
if (!completer->currentItem()->flags().testFlag(Qt::ItemIsSelectable)) return;
QString ins = completer->currentItem()->text(1), ret = completer->currentItem()->text(0);
QTextCursor tc = ui->textCode->textCursor(), stc = tc;
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
bool ins_br = true, shifted = false;
if (!tc.selectedText().isEmpty()) {
// if (tc.selectedText()[0].isSpace()) {
if (!tc.selectedText()[0].isLetterOrNumber() && !tc.selectedText()[0].isSpace() && !(tc.selectedText()[0] == '_')) {
stc.movePosition(QTextCursor::Left);
shifted = true;
} else {
tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::EndOfWord);
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
}
if (!tc.selectedText().isEmpty())
if (tc.selectedText()[0].toLatin1() == '(')
ins_br = false;
}
if (ins.contains("("))
ins = ins.left(ins.indexOf("(")) + "()";
if (!ins_br && ins.endsWith("()"))
ins.chop(2);
tc = stc;
tc.select(QTextCursor::WordUnderCursor);
if (!tc.selectedText().leftJustified(1)[0].isLetterOrNumber() && !(tc.selectedText().leftJustified(1)[0] == '_')) {
tc = stc;
if (shifted)
tc.movePosition(QTextCursor::Right);
}
ui->textCode->setTextCursor(tc);
ui->textCode->textCursor().insertText(ins);
tc = ui->textCode->textCursor();
if (ins_br) {
if (ret == "void") {
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
if (tc.selectedText() != ";") {
ui->textCode->textCursor().insertText(";");
tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2);
}
}
if (ins.endsWith(")") && !completer->currentItem()->text(1).endsWith("()")) {
tc.movePosition(QTextCursor::Left);
ui->textCode->setTextCursor(tc);
}
} else {
if (completer->currentItem()->text(1).endsWith(")")) {
tc.movePosition(QTextCursor::Right);
ui->textCode->setTextCursor(tc);
}
if (completer->currentItem()->text(1).endsWith("()")) {
tc.movePosition(QTextCursor::Right);
ui->textCode->setTextCursor(tc);
}
}
completer->hide();
}
void QCodeEdit::textEdit_cursorPositionChanged() {
es_line.cursor = ui->textCode->textCursor();
es_line.cursor.select(QTextCursor::LineUnderCursor);
es_line.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
highlightBrackets();
applyExtraSelection();
}
void QCodeEdit::textEdit_textChanged() {
if (_replacing) return;
searchAll();
updateLines();
}
void QCodeEdit::textEdit_selectionChanged() {
es_selected.clear();
QString sf = ui->textCode->textCursor().selectedText();
if (sf.trimmed().isEmpty() || sf.contains("\n")) {
applyExtraSelection();
return;
}
QTextCursor tc(ui->textCode->document()->begin());
QTextEdit::ExtraSelection es;
es.format.setBackground(QColor(251, 250, 150));
while (true) {
tc = ui->textCode->document()->find(sf, tc, QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords);
if (tc.isNull()) break;
es.cursor = tc;
es_selected << es;
}
applyExtraSelection();
}
void QCodeEdit::setShowSpaces(bool yes) {
spaces_ = yes;
QTextOption to = ui->textCode->document()->defaultTextOption();
QTextOption::Flags tof = to.flags();
if (yes) tof |= QTextOption::ShowTabsAndSpaces;
else tof &= ~QTextOption::ShowTabsAndSpaces;
to.setFlags(tof);
ui->textCode->document()->setDefaultTextOption(to);
}
void QCodeEdit::setShowLineNumbers(bool yes) {
ui->textLines->setVisible(yes);
}
void QCodeEdit::search(const QString & t) {
ui->widgetSearch->show();
ui->comboSearch->setEditText(QString());
ui->comboSearch->setEditText(t);
ui->comboSearch->setFocus();
//searchAll();
searchNext(false);
}
void QCodeEdit::searchNext(bool next) {
if (es_search_list.isEmpty())
return;
cur_search_ind = searchIndFromCursor() + (next ? 1 : 0);
moveToSearch();
}
void QCodeEdit::searchPrevious() {
if (es_search_list.isEmpty())
return;
cur_search_ind = searchIndFromCursor() - 1;
moveToSearch();
}
void QCodeEdit::hideSearch() {
ui->widgetSearch->hide();
searchAll();
}
void QCodeEdit::on_comboSearch_currentTextChanged(const QString & t) {
searchAll();
searchNext(false);
}
void QCodeEdit::on_buttonReplace_clicked() {
if (es_search_list.isEmpty() || cur_search_ind < 0 || cur_search_ind >= es_search_list.size()) return;
if (ui->textCode->textCursor() != es_search_list[cur_search_ind].cursor) return;
if (ui->textCode->textCursor().selectedText().size() != es_search_list[cur_search_ind].cursor.selectedText().size()) return;
ui->textCode->textCursor().insertText(ui->comboReplace->currentText());
}
void QCodeEdit::on_buttonReplaceSearch_clicked() {
on_buttonReplace_clicked();
searchNext();
}
void QCodeEdit::on_buttonReplaceAll_clicked() {
_replacing = true;
QString rt = ui->comboReplace->currentText();
for (int i = es_search_list.size() - 1; i >= 0; --i)
es_search_list[i].cursor.insertText(rt);
_replacing = false;
textEdit_textChanged();
}

View File

@@ -0,0 +1,163 @@
#ifndef QCODEEDIT_H
#define QCODEEDIT_H
#include <QDebug>
#include <QPlainTextEdit>
#include <QTreeWidget>
#include <QScrollBar>
#include "iconedlabel.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
namespace Ui {
class QCodeEdit;
}
class QCodeEdit: public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool showSpaces READ showSpaces WRITE setShowSpaces)
Q_PROPERTY(bool showLineNumbers READ showLineNumbers WRITE setShowLineNumbers)
Q_PROPERTY(QFont editorFont READ editorFont WRITE setEditorFont)
public:
QCodeEdit(QWidget * parent = 0);
~QCodeEdit();
enum ACClassType {
Keyword,
Function,
Namespace
};
QTextCursor textCursor() const;
QTextDocument * document() const;
void setDocument(QTextDocument * doc);
void setTextCursor(const QTextCursor & c);
void centerCursor();
void insertText(const QString & text);
void appendText(const QString & text);
void setCustomExtraSelection(const QList<QTextEdit::ExtraSelection> & es);
QRect cursorRect() const;
QRect cursorRect(const QTextCursor & cursor) const;
QString text() const;
QStringList cursorScope() const;
bool showSpaces() const {return spaces_;}
bool showLineNumbers() const;
void setEditorFont(QFont f);
QFont editorFont() const;
QPlainTextEdit * textEdit() const;
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon()) {ac_classes[id] = ACClass(id, ac_class, name, icon);}
protected:
typedef QPair<QString, QString> StringsPair;
typedef QPair<int, QList<StringsPair> > ACPair;
typedef QList<ACPair> ACList;
virtual ACList autoCompletitionList(const QStringList & scope, const QString & written) const {return ACList();}
virtual void parse() {}
virtual void documentUnset() {}
virtual void documentChanged(QTextDocument * d) {}
QString selectArg(QString s, int arg);
void raiseHelp(QTextCursor tc, int arg = -1);
QTextCursor functionStart(QTextCursor tc, int * arg);
ACList wordsCompletitionList(const QString & written) const;
QPair<QStringList, QString> getScope(QTextCursor tc, bool * ok = 0);
static int skipRange(const QString & s, int pos, QChar oc, QChar cc, QChar sc = QChar());
static int skipCWord(const QString & s, int pos);
static bool matchWritten(QString s, QString w);
static QChar pairChar(QChar c);
Ui::QCodeEdit * ui;
private:
struct 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) {}
int id;
ACClassType class_;
QString name;
QIcon icon;
};
QTreeWidget * completer;
IconedLabel * lbl_help[2];
QFrame * widget_help;
QTextEdit::ExtraSelection es_line, es_cursor, es_bracket, es_range, es_search;
QList<QTextEdit::ExtraSelection> es_selected, es_custom, es_brackets, es_search_list;
QMap<int, ACClass> ac_classes;
QStringList cursor_scope;
int prev_lc, auto_comp_pl, timer, cur_search_ind, pos_press, pos_el_press;
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
bool eventFilter(QObject * o, QEvent * e);
void showEvent(QShowEvent * );
void timerEvent(QTimerEvent * );
void leaveEvent(QEvent * );
void highlightBrackets();
void applyExtraSelection();
void nextCompletition();
void previousCompletition();
void clearSearch();
void moveToSearch();
int searchIndFromCursor();
private slots:
void syncScrolls();
void scrollUp();
void scrollDown();
void hideHelp();
void deleteLine();
void copyLineUp();
void copyLineDown();
void moveLineUp();
void moveLineDown();
void indent();
void deindent();
void autoIndent();
void invokeAutoCompletition(bool force = false);
void commitCompletition();
void searchAll();
void search_triggered();
void textEdit_cursorPositionChanged();
void textEdit_textChanged();
void textEdit_selectionChanged();
void on_comboSearch_currentTextChanged(const QString & t);
void on_buttonReplace_clicked();
void on_buttonReplaceSearch_clicked();
void on_buttonReplaceAll_clicked();
public slots:
void updateLines();
void scrollToTop();
void newLine();
void newLineBefore();
void setFocus();
void setText(const QString & t);
void setShowSpaces(bool yes);
void setShowLineNumbers(bool yes);
void search(const QString & t);
void searchNext(bool next = true);
void searchPrevious();
void hideSearch();
signals:
void textChanged();
void parseRequest();
};
//Q_DECLARE_OPERATORS_FOR_FLAGS(QPIConsole::Formats)
QT_END_NAMESPACE
QT_END_HEADER
#endif // QCODEEDIT_H

View File

@@ -0,0 +1,388 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QCodeEdit</class>
<widget class="QWidget" name="QCodeEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>726</width>
<height>577</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="textLines">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="textCode">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="tabChangesFocus">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widgetSearch" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Search:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QToolButton" name="buttonSearchCase">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Case sensitive</string>
</property>
<property name="text">
<string>Aa</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonSearchWord">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Whole words</string>
</property>
<property name="text">
<string>W</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonSearchPrev">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Previous</string>
</property>
<property name="icon">
<iconset resource="../../../SHS/src/designers/SH_designer/SH_designer.qrc">
<normaloff>:/icons/go-previous.png</normaloff>:/icons/go-previous.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonSearchNext">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Next</string>
</property>
<property name="icon">
<iconset resource="../../../SHS/src/designers/SH_designer/SH_designer.qrc">
<normaloff>:/icons/go-next.png</normaloff>:/icons/go-next.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Replace:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QToolButton" name="buttonReplace">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Replace</string>
</property>
<property name="text">
<string>R</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonReplaceSearch">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Replace and search</string>
</property>
<property name="text">
<string>Rs</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonReplaceAll">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Replace all</string>
</property>
<property name="text">
<string>Ra</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="EComboBox" name="comboSearch">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="EComboBox" name="comboReplace">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>EComboBox</class>
<extends>QComboBox</extends>
<header>ecombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonSearchNext</sender>
<signal>clicked()</signal>
<receiver>QCodeEdit</receiver>
<slot>searchNext()</slot>
<hints>
<hint type="sourcelabel">
<x>723</x>
<y>670</y>
</hint>
<hint type="destinationlabel">
<x>731</x>
<y>578</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonSearchPrev</sender>
<signal>clicked()</signal>
<receiver>QCodeEdit</receiver>
<slot>searchPrevious()</slot>
<hints>
<hint type="sourcelabel">
<x>691</x>
<y>670</y>
</hint>
<hint type="destinationlabel">
<x>743</x>
<y>536</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonSearchCase</sender>
<signal>toggled(bool)</signal>
<receiver>QCodeEdit</receiver>
<slot>searchAll()</slot>
<hints>
<hint type="sourcelabel">
<x>612</x>
<y>654</y>
</hint>
<hint type="destinationlabel">
<x>740</x>
<y>499</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonSearchWord</sender>
<signal>toggled(bool)</signal>
<receiver>QCodeEdit</receiver>
<slot>searchAll()</slot>
<hints>
<hint type="sourcelabel">
<x>648</x>
<y>658</y>
</hint>
<hint type="destinationlabel">
<x>753</x>
<y>511</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>search(QString)</slot>
<slot>searchNext()</slot>
<slot>searchPrevious()</slot>
<slot>searchAll()</slot>
<slot>hideSearch()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,82 @@
#include "qipedit.h"
QIPEdit::QIPEdit(QWidget * parent, const QString & ip): QWidget(parent) {
layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);
QIntValidator * validator = new QIntValidator(0, 255, this);
for (int i = 0; i < 4; i++) {
edits.push_back(new QLineEdit(this));
edits.back()->setAlignment(Qt::AlignHCenter);
edits.back()->setMaxLength(3);
edits.back()->setValidator(validator);
edits.back()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(edits.back());
if (i < 3) {
dots.push_back(new QLabel(this));
dots.back()->setText(".");
dots.back()->adjustSize();
layout->addWidget(dots.back());
}
}
//for (int i = 0; i < 3; i++) edits[i]->setTabOrder(edits[i+1], edits[i]);
connect(edits[0], SIGNAL(returnPressed()), this, SLOT(returnPressed0()));
connect(edits[1], SIGNAL(returnPressed()), this, SLOT(returnPressed1()));
connect(edits[2], SIGNAL(returnPressed()), this, SLOT(returnPressed2()));
connect(edits[3], SIGNAL(returnPressed()), this, SLOT(returnPressed3()));
connect(edits[0], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged0(const QString & )));
connect(edits[1], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged1(const QString & )));
connect(edits[2], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged2(const QString & )));
connect(edits[3], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged3(const QString & )));
setLayout(layout);
setIP(ip);
cind = 0;
}
QIPEdit::~QIPEdit() {
foreach (QLineEdit * i, edits)
delete i;
foreach (QLabel * i, dots)
delete i;
edits.clear();
dots.clear();
delete layout;
}
void QIPEdit::setIP(const QString & text) {
QString s, str = 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('.'));
edits[1]->setText(s == "" ? "0" : s);
str = str.right(str.length() - s.length() - 1);
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);
}
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();
return s;
}
void QIPEdit::returnPress(int index) {
if (index < 3) {
edits[index + 1]->setFocus();
edits[index + 1]->setSelection(0, 3);
}
}

View File

@@ -0,0 +1,48 @@
#ifndef QIPEDIT_H
#define QIPEDIT_H
#include <QVector>
#include <QBoxLayout>
#include <QIntValidator>
#include <QFocusEvent>
#include <QLineEdit>
#include <QLabel>
class QIPEdit: public QWidget
{
Q_OBJECT
Q_PROPERTY(QString IP READ IP WRITE setIP)
public:
QIPEdit(QWidget * parent = 0, const QString & ip = "");
~QIPEdit();
QString IP();
private:
void returnPress(int index);
inline void textChange(int index, const QString & text) {if (text.length() == 3 && isVisible()) returnPress(index); emit valueChanged(IP());}
int cind;
QBoxLayout * layout;
QVector<QLineEdit * > edits;
QVector<QLabel * > dots;
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);}
signals:
void valueChanged(QString);
};
#endif // QIPEDIT_H

View File

@@ -0,0 +1,77 @@
#include "qpiconfignewdialog.h"
#include "ui_qpiconfignewdialog.h"
QPIConfigNewDialog::QPIConfigNewDialog(QWidget * parent): QDialog(parent) {
ui = new Ui::QPIConfigNewDialog();
ui->setupUi(this);
radios = findChildren<QRadioButton * >();
ui->widgetValue->hideAll();
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
void QPIConfigNewDialog::changeEvent(QEvent * e) {
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void QPIConfigNewDialog::typeChanged() {
foreach (QRadioButton * i, radios) {
if (i->isChecked()) {
ui->widgetValue->setType(i->property("type").toString());
return;
}
}
}
QString QPIConfigNewDialog::type() {
foreach (QRadioButton * i, radios)
if (i->isChecked())
return i->property("type").toString();
return " ";
}
void QPIConfigNewDialog::reset(bool node) {
ui->lineName->clear();
ui->lineComment->clear();
ui->radioType_0->setChecked(true);
ui->lineName->setFocus();
ui->widgetValue->setType("s");
ui->widgetValue->value.clear();
ui->widgetValue->setVisible(!node);
ui->groupType->setVisible(!node);
ui->labelValue->setVisible(!node);
ui->labelComment->setVisible(!node);
ui->lineComment->setVisible(!node);
adjustSize();
}
QString QPIConfigNewDialog::name() {
return ui->lineName->text();
}
QString QPIConfigNewDialog::value() {
return ui->widgetValue->value;
}
QString QPIConfigNewDialog::comment() {
return ui->lineComment->text();
}
void QPIConfigNewDialog::on_lineName_textChanged(const QString & text) {
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
}

View File

@@ -0,0 +1,40 @@
#ifndef QPICONFIGNEWDIALOG_H
#define QPICONFIGNEWDIALOG_H
#include <QDialog>
#include <QRadioButton>
namespace Ui {
class QPIConfigNewDialog;
}
class QPIConfigNewDialog: public QDialog
{
Q_OBJECT
public:
QPIConfigNewDialog(QWidget * parent = 0);
QString type();
QString name();
QString value();
QString comment();
void reset(bool node = false);
protected:
void changeEvent(QEvent * e);
Ui::QPIConfigNewDialog * ui;
private slots:
void on_lineName_textChanged(const QString & text);
void typeChanged();
private:
QList<QRadioButton * > radios;
};
#endif // QPICONFIGNEWDIALOG_H

View File

@@ -0,0 +1,432 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QPIConfigNewDialog</class>
<widget class="QDialog" name="QPIConfigNewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>316</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupType">
<property name="title">
<string>Type</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radioType_0">
<property name="text">
<string>string</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="type" stdset="0">
<string>s</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioType_1">
<property name="text">
<string>integer</string>
</property>
<property name="type" stdset="0">
<string>n</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radioType_2">
<property name="text">
<string>float</string>
</property>
<property name="type" stdset="0">
<string>f</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="radioType_3">
<property name="text">
<string>string list</string>
</property>
<property name="type" stdset="0">
<string>l</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="radioType_4">
<property name="text">
<string>boolean</string>
</property>
<property name="type" stdset="0">
<string>b</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QRadioButton" name="radioType_5">
<property name="text">
<string>color</string>
</property>
<property name="type" stdset="0">
<string>c</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radioType_6">
<property name="text">
<string>rectangle</string>
</property>
<property name="type" stdset="0">
<string>r</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="radioType_7">
<property name="text">
<string>area</string>
</property>
<property name="type" stdset="0">
<string>a</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radioType_8">
<property name="text">
<string>point</string>
</property>
<property name="type" stdset="0">
<string>p</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="radioType_9">
<property name="text">
<string>vector</string>
</property>
<property name="type" stdset="0">
<string>v</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QRadioButton" name="radioType_10">
<property name="text">
<string>ip</string>
</property>
<property name="type" stdset="0">
<string>i</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineName"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelComment">
<property name="text">
<string>Comment:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelValue">
<property name="text">
<string>Value:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineComment"/>
</item>
<item row="2" column="1">
<widget class="ConfigValueWidget" name="widgetValue" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ConfigValueWidget</class>
<extends>QWidget</extends>
<header>qpiconfigvaluewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>lineName</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>126</x>
<y>326</y>
</hint>
<hint type="destinationlabel">
<x>110</x>
<y>231</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>169</x>
<y>326</y>
</hint>
<hint type="destinationlabel">
<x>149</x>
<y>232</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_0</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>33</x>
<y>70</y>
</hint>
<hint type="destinationlabel">
<x>1</x>
<y>61</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_1</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>25</x>
<y>88</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>99</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_2</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>17</x>
<y>119</y>
</hint>
<hint type="destinationlabel">
<x>2</x>
<y>130</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_3</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>26</x>
<y>143</y>
</hint>
<hint type="destinationlabel">
<x>0</x>
<y>165</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_4</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>50</x>
<y>170</y>
</hint>
<hint type="destinationlabel">
<x>2</x>
<y>195</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_5</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>243</x>
<y>37</y>
</hint>
<hint type="destinationlabel">
<x>312</x>
<y>10</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_6</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>275</x>
<y>67</y>
</hint>
<hint type="destinationlabel">
<x>315</x>
<y>40</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_7</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>262</x>
<y>95</y>
</hint>
<hint type="destinationlabel">
<x>311</x>
<y>72</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_8</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>250</x>
<y>113</y>
</hint>
<hint type="destinationlabel">
<x>313</x>
<y>104</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_9</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>286</x>
<y>145</y>
</hint>
<hint type="destinationlabel">
<x>311</x>
<y>138</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioType_10</sender>
<signal>clicked()</signal>
<receiver>QPIConfigNewDialog</receiver>
<slot>typeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>273</x>
<y>168</y>
</hint>
<hint type="destinationlabel">
<x>312</x>
<y>167</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>typeChanged()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,98 @@
#include "qpiconfigvaluewidget.h"
#include "qpievaluator.h"
ConfigValueWidget::ConfigValueWidget(QWidget * parent): QWidget(parent), lay(QBoxLayout::Down, this) {
lay.setContentsMargins(0, 0, 0, 0);
w_integer.setRange(INT_MIN, INT_MAX);
w_float.setRange(-DBL_MAX, DBL_MAX);
w_float.setDecimals(5);
active = true;
lay.addWidget(&w_string);
lay.addWidget(&w_list);
lay.addWidget(&w_bool);
lay.addWidget(&w_integer);
lay.addWidget(&w_float);
lay.addWidget(&w_color);
lay.addWidget(&w_rect);
lay.addWidget(&w_point);
lay.addWidget(&w_ip);
lay.addWidget(&w_enum);
lay.addWidget(&w_path);
connect(&w_string, SIGNAL(textChanged(QString)), this, SLOT(valueChanged()));
connect(&w_list, SIGNAL(valueChanged()), this, SLOT(valueChanged()));
connect(&w_bool, SIGNAL(toggled(bool)), this, SLOT(valueChanged()));
connect(&w_integer, SIGNAL(valueChanged(int)), this, SLOT(valueChanged()));
connect(&w_float, SIGNAL(valueChanged(double)), this, SLOT(valueChanged()));
connect(&w_color, SIGNAL(colorChanged(QColor)), this, SLOT(valueChanged()));
connect(&w_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(valueChanged()));
connect(&w_point, SIGNAL(valueChanged(QPointF)), this, SLOT(valueChanged()));
connect(&w_ip, SIGNAL(valueChanged(QString)), this, SLOT(valueChanged()));
connect(&w_enum, SIGNAL(currentIndexChanged(int)), this, SLOT(valueChanged()));
connect(&w_path, SIGNAL(valueChanged()), this, SLOT(valueChanged()));
}
void ConfigValueWidget::setType(const QString & t) {
hideAll();
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;}
}
void ConfigValueWidget::setValue(const QString & 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;}
w_string.setText(v);
active = true;
}
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;}
value = w_string.text();
emit changed(this, value);
}

View File

@@ -0,0 +1,58 @@
#ifndef QPICONFIGVALUEWIDGET_H
#define QPICONFIGVALUEWIDGET_H
#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 <QPushButton>
#include <QCheckBox>
#include <QSpinBox>
#include <QDoubleSpinBox>
class ConfigValueWidget: public QWidget
{
Q_OBJECT
friend class QPIConfigWidget;
friend class QPIConfigNewDialog;
public:
ConfigValueWidget(QWidget * parent = 0);
~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());}
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();}
QString type, value, full_name, comment;
bool active;
QBoxLayout lay;
CLineEdit w_string;
StringListEdit w_list;
ColorButton w_color;
QCheckBox w_bool;
QSpinBox w_integer;
QDoubleSpinBox w_float;
QRectEdit w_rect;
QPointEdit w_point;
QIPEdit w_ip;
QComboBox w_enum;
PathEdit w_path;
private slots:
void valueChanged();
signals:
void changed(ConfigValueWidget * , QString );
};
#endif // QPICONFIGVALUEWIDGET_H

View File

@@ -0,0 +1,380 @@
#include "qpiconfigwidget.h"
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);
setColumnWidth(0, 150);
setColumnWidth(1, 200);
} else setColumnCount(0);
setSelectionMode(ExtendedSelection);
setVerticalScrollMode(ScrollPerPixel);
actionAddItem.setIcon(QIcon(":/icons/item-add.png"));
actionAddNode.setIcon(QIcon(":/icons/node-add.png"));
actionToItem.setIcon(QIcon(":/icons/item.png"));
actionToNode.setIcon(QIcon(":/icons/node.png"));
actionRemove.setIcon(QIcon(":/icons/edit-delete.png"));
popupMenu.addAction(&actionAddItem);
popupMenu.addAction(&actionAddNode);
popupMenu.addSeparator();
/*popupMenu.addAction(&actionToItem);
popupMenu.addAction(&actionToNode);
popupMenu.addSeparator();*/
popupMenu.addAction(&actionRemove);
popupMenu.addSeparator();
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(&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()));
connect(&actionExpandAll, SIGNAL(triggered()), this, SLOT(expandAll()));
connect(&actionCollapseAll, SIGNAL(triggered()), this, SLOT(collapseAll()));
read_only_name = read_only_value = read_only_type = read_only_comment = false;
c_hidden << false << false << false << false;
pi = c_pi = 0;
translate();
setQPIConfig(c);
//resize(600, 400);
//show();
}
void QPIConfigWidget::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
translate();
return;
}
//for (int i = 0; i < 4; ++i)
// setColumnHidden(i, c_hidden[i]);
QTreeWidget::changeEvent(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) {
qApp->processEvents();
itemClicked(pi, 1);
popupMenu.popup(((QMouseEvent * )e)->globalPos());
}
}
}
return QTreeWidget::eventFilter(o, e);
}
void QPIConfigWidget::itemClicked(QTreeWidgetItem * item, int column) {
if (item != 0) {
if ((column == 0 && !read_only_name) || (column == 3 && !read_only_comment)) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
bool node = true, ro = read_only_name || read_only_type || read_only_value;
if (item != 0)
if (itemTWidget(item) != 0)
if (itemTWidget(item)->isEnabled())
node = false;
actionAddItem.setVisible(node && !ro);
actionAddNode.setVisible(node && !ro);
actionRemove.setVisible(!ro && !selectedItems().isEmpty());
}
void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
if (item != c_pi) {
c_pi = item;
if (item != 0) {
c_name = item->text(0);
c_comment = item->text(3);
}
return;
}
if (item == 0) return;
if (c_name == item->text(0) && c_comment == item->text(3)) return;
//qDebug() << "change" << item->text(0);
QPIConfig::Entry * e = itemEntry(item);
if (e == 0) return;
if (column == 0) {
buildFullNames(item);
e->setName(item->text(column));
conf->buildFullNames(e->parent());
//qDebug() << itemCWidget(item)->full_name;
}
if (column == 3) e->setComment(item->text(column));
c_name = item->text(0);
c_comment = item->text(3);
emit changed();
}
void QPIConfigWidget::typeChange(int t, UComboBox * c) {
ConfigValueWidget * cw = (ConfigValueWidget * )c->property("qpic_widget").toLongLong();
cw->setType(types.key(s_types[t]));
conf->getValue(cw->full_name).setType(types.key(s_types[t]));
emit changed();
}
void QPIConfigWidget::valueChange(ConfigValueWidget * w, QString v) {
conf->getValue(w->full_name).setValue(v);
emit changed();
}
void QPIConfigWidget::on_actionAddItem_triggered() {
if (conf == 0 || !active) return;
QString fp;
if (pi == 0) pi = invisibleRootItem();
else fp = itemCWidget(pi)->full_name + conf->delim;
new_dialog.reset();
if (new_dialog.exec() == QDialog::Rejected) return;
QPIConfig::Entry * e;
if (pi->childCount() == 0) {
//qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
conf->removeEntry(itemCWidget(pi)->full_name, false);
}
//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);
pi->setText(0, new_dialog.name());
pi->setText(3, new_dialog.comment());
int ind = s_types.indexOf(types[new_dialog.type()]);
if (ind < 0) w_types.back()->setCurrentIndex(0);
else w_types.back()->setCurrentIndex(ind);
emit changed();
}
void QPIConfigWidget::on_actionAddNode_triggered() {
if (conf == 0 || !active) return;
QString fp;
if (pi == 0) pi = invisibleRootItem();
else fp = itemCWidget(pi)->full_name + conf->delim;
new_dialog.reset(true);
if (new_dialog.exec() == QDialog::Rejected) return;
QPIConfig::Entry e;
//e = &(conf->addEntry(fp + new_dialog.name(), "", "", false));
e._full_name = fp + new_dialog.name();
expandItem(pi);
pi = addEntry(pi, &e, true);
pi->setText(0, new_dialog.name());
pi->setText(3, new_dialog.comment());
setItemWidget(pi, 2, 0);
emit changed();
}
void QPIConfigWidget::on_actionRemove_triggered() {
//hide();
if (conf == 0 || !active) return;
QList<QTreeWidgetItem * > si = selectedItems();
conf->buildFullNames(&(conf->root));
QPIConfig::Entry * e;
foreach (QTreeWidgetItem * i, si) {
e = itemEntry(i);
if (e == 0) continue;
//qDebug() << "remove " + e->_full_name;
conf->removeEntry(e->_full_name, false);
deleteEntry(i);
}
emit changed();
//show();
}
void QPIConfigWidget::clear() {
if (!active) return;
bool hidden = isHidden();
hide();
QTreeWidget::clear();
foreach (ConfigValueWidget * i, w_values)
delete i;
foreach (QComboBox * i, w_types)
delete i;
w_values.clear();
w_types.clear();
if (!hidden) show();
}
void QPIConfigWidget::buildTree() {
if (!active) return;
if (conf == 0) return;
bool hidden = isHidden();
hide();
clear();
conf->buildFullNames(&(conf->root));
buildEntry(invisibleRootItem(), &conf->rootEntry());
if (!hidden) show();
}
void QPIConfigWidget::setReadOnlyValue(bool yes) {
read_only_value = yes;
foreach (ConfigValueWidget * i, w_values)
i->setEnabled(!yes);
}
void QPIConfigWidget::setReadOnlyType(bool yes) {
read_only_type = yes;
foreach (QComboBox * i, w_types) {
i->setEnabled(!yes);
i->setFrame(!yes);
}
}
void QPIConfigWidget::buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e) {
foreach (QPIConfig::Entry * j, e->children())
buildEntry(addEntry(i, j, !j->isLeaf()), j);
}
void QPIConfigWidget::buildFullNames(QTreeWidgetItem * i) {
ConfigValueWidget * cw, * pw;
cw = itemCWidget(i);
if (i->parent() != 0) {
pw = itemCWidget(i->parent());
cw->full_name = pw->full_name + conf->delim + i->text(0);
} else cw->full_name = i->text(0);
for (int j = 0; j < i->childCount(); ++j)
buildFullNames(i->child(j));
}
QPIConfig::Entry * QPIConfigWidget::itemEntry(QTreeWidgetItem * i) {
ConfigValueWidget * cfw = itemCWidget(i);
if (cfw == 0) return 0;
return &(conf->getValue(cfw->full_name));
}
QTreeWidgetItem * QPIConfigWidget::addEntry(QTreeWidgetItem * i, QPIConfig::Entry * e, bool node) {
if (conf == 0) return 0;
ti = new QTreeWidgetItem();
ti->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ti->setSizeHint(0, QSize(26, 26));
ti->setText(0, e->name());
ti->setText(3, e->comment());
w_values.push_back(new ConfigValueWidget);
w_values.back()->setEntry(e);
w_values.back()->setEnabled(!read_only_value);
if (!node) {
w_types.push_back(new UComboBox());
w_types.back()->addItems(s_types);
w_types.back()->setCurrentIndex(s_types.indexOf(types[e->type().leftJustified(1).left(1)]));
w_types.back()->setProperty("qpic_widget", QVariant((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_values.back(), SIGNAL(changed(ConfigValueWidget * , QString)), this, SLOT(valueChange(ConfigValueWidget * , QString)));
i->addChild(ti);
setItemWidget(ti, 1, w_values.back());
if (!node) {
setItemWidget(ti, 2, w_types.back());
if (itemTWidget(i) != 0) { //itemTWidget(i)->setEnabled(false);
w_types.remove(w_types.indexOf(itemTWidget(i)));
setItemWidget(i, 2, 0);
}
}
return ti;
}
void QPIConfigWidget::deleteEntry(QTreeWidgetItem * i) {
ConfigValueWidget * vw;
UComboBox * cb;
int cc = i->childCount();
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));
if (vw != 0) {
w_values.remove(w_values.indexOf(vw));
delete vw;
}
if (cb != 0) {
w_types.remove(w_types.indexOf(cb));
delete cb;
}
delete i;
}
bool QPIConfigWidget::filter(const QString & f, QTreeWidgetItem * i) {
if (i->childCount() == 0) return filterItem(f, i);
bool found = false;
for (int j = 0; j < i->childCount(); ++j)
if (filter(f, i->child(j))) found = true;
i->setHidden(!found);
return found;
}
bool QPIConfigWidget::filterItem(const QString & f, QTreeWidgetItem * i) {
if (f.isEmpty()) {
i->setHidden(false);
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);
if (itemTWidget(i) != 0)
ret = ret || (!isColumnHidden(2) && itemTWidget(i)->currentText().indexOf(f, 0, Qt::CaseInsensitive) >= 0);
i->setHidden(!ret);
return ret;
}
void QPIConfigWidget::translate() {
QStringList l;
l << tr("Name") << tr("Value") << tr("Type") << tr("Comment");
if (active) setHeaderLabels(l);
types.clear();
s_types.clear();
addTrEntry("s", tr("string"));
addTrEntry("l", tr("string list"));
addTrEntry("n", tr("integer"));
addTrEntry("f", tr("float"));
addTrEntry("b", tr("boolean"));
addTrEntry("c", tr("color"));
addTrEntry("r", tr("rectangle"));
addTrEntry("a", tr("area"));
addTrEntry("p", tr("point"));
addTrEntry("v", tr("vector"));
addTrEntry("i", tr("ip"));
actionAddItem.setText(tr("Add item ..."));
actionAddNode.setText(tr("Add node ..."));
actionToItem.setText(tr("Convert to item"));
actionToNode.setText(tr("Convert to node"));
actionRemove.setText(tr("Remove"));
actionExpandAll.setText(tr("Expand all"));
actionCollapseAll.setText(tr("Collapse all"));
if (!active) return;
for (int i = 0; i < 4; ++i)
setColumnHidden(i, c_hidden[i]);
}
QString QPIConfigWidget::writeToString() {
if (conf == 0) return QString();
conf->buildFullNames(&(conf->root));
return conf->writeAllToString();
}
void QPIConfigWidget::readFromString(QString str) {
if (conf == 0) return;
conf->readAllFromString(str);
buildTree();
}

View File

@@ -0,0 +1,111 @@
#ifndef QPICONFIGWIDGET_H
#define QPICONFIGWIDGET_H
#include "qpiconfig.h"
#include "qpiconfignewdialog.h"
#include "qpiconfigvaluewidget.h"
#include <QTreeWidget>
#include <QComboBox>
#include <QEvent>
#include <QBoxLayout>
#include <QAction>
#include <QMenu>
class UComboBox: public QComboBox
{
Q_OBJECT
public:
UComboBox(QWidget * parent = 0): QComboBox(parent) {connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChange(int)));}
private slots:
void indexChange(int i) {emit currentIndexChanged(i, this);}
signals:
void currentIndexChanged(int, UComboBox * );
};
class QPIConfigWidget: public QTreeWidget
{
Q_OBJECT
Q_PROPERTY(bool readOnlyName READ readOnlyName WRITE setReadOnlyName)
Q_PROPERTY(bool readOnlyValue READ readOnlyValue WRITE setReadOnlyValue)
Q_PROPERTY(bool readOnlyType READ readOnlyType WRITE setReadOnlyType)
Q_PROPERTY(bool readOnlyComment READ readOnlyComment WRITE setReadOnlyComment)
Q_PROPERTY(bool columnNameVisible READ columnNameVisible WRITE setColumnNameVisible)
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 = 0, QPIConfig * c = 0, bool on = true);
~QPIConfigWidget() {clear();}
void setQPIConfig(QPIConfig * c) {conf = c; buildTree();}
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);
private:
void changeEvent(QEvent * e);
bool eventFilter(QObject * o, QEvent * e);
void buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e);
void buildFullNames(QTreeWidgetItem * i);
QPIConfig::Entry * itemEntry(QTreeWidgetItem * i);
ConfigValueWidget * itemCWidget(QTreeWidgetItem * i) {return qobject_cast<ConfigValueWidget * >(itemWidget(i, 1));}
UComboBox * itemTWidget(QTreeWidgetItem * i) {return qobject_cast<UComboBox * >(itemWidget(i, 2));}
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) {types.insert(s, f); s_types << 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;
QHash<QString, QString> types;
QStringList s_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;
public slots:
void parse() {if (conf == 0) clear(); else conf->readAll();}
void write() {if (conf == 0) return; conf->buildFullNames(&(conf->root)); conf->writeAll();}
void clear();
void buildTree();
void filter(const QString & f) {if (!active) return; filter(f, invisibleRootItem());}
void setReadOnlyName(bool yes) {read_only_name = yes;}
void setReadOnlyValue(bool yes);
void setReadOnlyType(bool yes);
void setReadOnlyComment(bool yes) {read_only_comment = yes;}
void setColumnNameVisible(bool yes) {setColumnHidden(0, !yes); c_hidden[0] = !yes;}
void setColumnValueVisible(bool yes) {setColumnHidden(1, !yes); c_hidden[1] = !yes;}
void setColumnTypeVisible(bool yes) {setColumnHidden(2, !yes); c_hidden[2] = !yes;}
void setColumnCommentVisible(bool yes) {setColumnHidden(3, !yes); c_hidden[3] = !yes;}
private slots:
void itemClicked(QTreeWidgetItem * item, int column);
void itemChanged(QTreeWidgetItem * item, int column);
void typeChange(int t, UComboBox * c);
void valueChange(ConfigValueWidget * w, QString v);
void on_actionAddItem_triggered();
void on_actionAddNode_triggered();
void on_actionRemove_triggered();
signals:
void changed();
};
#endif // QPICONFIGWIDGET_H

View File

@@ -0,0 +1,268 @@
#include "qpiconsole.h"
QPIConsole::QPIConsole(QWidget * parent): QTabWidget(parent) {
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
cur_tab = timer = -1;
def_align = Qt::AlignCenter;
}
void QPIConsole::timerEvent(QTimerEvent * ) {
for (int i = 0; i < columns().size(); ++i) {
Column & ccol(tabs[cur_tab].columns[i]);
QVector<Variable> & cvars(ccol.variables);
if (ccol.alignment.testFlag(Qt::AlignLeft)) {
ccol.layout->setLabelAlignment(Qt::AlignLeft);
} else {
ccol.layout->setLabelAlignment(Qt::AlignRight);
}
for (int j = 0; j < cvars.size(); ++j) {
Variable & tv(cvars[j]);
tv.label->setText(tv.name);
if (tv.type >= 0) {
if (ccol.alignment.testFlag(Qt::AlignLeft)) {
tv.label->setAlignment(Qt::AlignLeft);
if (tv.widget != 0) tv.widget->setAlignment(Qt::AlignLeft);
} else {
if (ccol.alignment.testFlag(Qt::AlignRight)) {
tv.label->setAlignment(Qt::AlignRight);
if (tv.widget != 0) tv.widget->setAlignment(Qt::AlignRight);
} else {
tv.label->setAlignment(Qt::AlignRight);
if (tv.widget != 0) tv.widget->setAlignment(Qt::AlignLeft);
}
}
}
if (tv.widget == 0) continue;
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;
default: break;
}
}
}
}
}
#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);
void QPIConsole::addString(const QString & name, int col, Formats format) {
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;
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 bool * ptr, int col, Formats format) {
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
void QPIConsole::addEmptyLine(int col, uint count) {
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;
lbl->setAlignment(column(col).alignment);
applyFormat(lbl, tv.format);
column(col).layout->addRow(lbl);
}
}
int QPIConsole::addTab(const QString & name, char bind_key) {
QWidget * w = new QWidget();
QVBoxLayout * lay = new QVBoxLayout();
QHBoxLayout * clay = new QHBoxLayout();
QLabel * lbl = new QLabel();
lay->setContentsMargins(2, 2, 2, 2);
clay->setContentsMargins(0, 0, 0, 0);
lay->addLayout(clay);
lay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Expanding));
lay->addWidget(lbl);
w->setLayout(lay);
QTabWidget::addTab(w, name);
tabs.push_back(Tab(name, bind_key));
tabs.back().layout = clay;
tabs.back().widget = lbl;
cur_tab = tabs.size() - 1;
setCurrentIndex(cur_tab);
return tabs.size();
}
void QPIConsole::checkColumn(int col) {
while (columns().size() < col) {
QFormLayout * lay = new QFormLayout();
lay->setContentsMargins(2, 2, 2, 2);
lay->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
columns().push_back(Column(def_align));
columns().back().layout = lay;
tabs[cur_tab].layout->addLayout(lay);
}
}
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];
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];
}
}
return ret;
}
const QString & QPIConsole::toBin(const void * d, int s) {
binstr.clear();
uchar cc, b;
for (int i = 0; i < s; ++i) {
cc = ((const uchar *)d)[i];
b = 1;
for (int j = 0; j < 8; ++j) {
binstr.prepend(cc & b ? "1" : "0");
b <<= 1;
}
if (i < s - 1) binstr.prepend(" ");
}
return binstr;
}
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);
if (f.testFlag(QPIConsole::Black)) fcol = Qt::black;
if (f.testFlag(QPIConsole::Red)) fcol = Qt::red;
if (f.testFlag(QPIConsole::Green)) fcol = Qt::green;
if (f.testFlag(QPIConsole::Yellow)) fcol = Qt::yellow;
if (f.testFlag(QPIConsole::Blue)) fcol = Qt::blue;
if (f.testFlag(QPIConsole::Magenta)) fcol = Qt::magenta;
if (f.testFlag(QPIConsole::Cyan)) fcol = Qt::cyan;
if (f.testFlag(QPIConsole::White)) fcol = Qt::white;
if (f.testFlag(QPIConsole::Lighter)) fcol = fcol.lighter(150);
if (f.testFlag(QPIConsole::Darker)) fcol = fcol.darker(150);
if (f.testFlag(QPIConsole::BackBlack)) bcol = Qt::black;
if (f.testFlag(QPIConsole::BackRed)) bcol = Qt::red;
if (f.testFlag(QPIConsole::BackGreen)) bcol = Qt::green;
if (f.testFlag(QPIConsole::BackYellow)) bcol = Qt::yellow;
if (f.testFlag(QPIConsole::BackBlue)) bcol = Qt::blue;
if (f.testFlag(QPIConsole::BackMagenta)) bcol = Qt::magenta;
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::Inverse)) {
QColor tc = fcol;
fcol = bcol;
bcol = tc;
}
l->setFont(fnt);
QPalette pal = palette();
pal.setColor(QPalette::WindowText, fcol);
pal.setColor(QPalette::Window, bcol);
l->setPalette(pal);
l->setAutoFillBackground(bcol != QColor(0xFFFFFF));
}
bool QPIConsole::removeTab(uint index) {
if (int(index) >= tabs.size()) return false;
delete QTabWidget::widget(index);
tabs.remove(index);
return true;
}
bool QPIConsole::setTab(uint index) {
if (int(index) >= tabs.size()) return false;
setCurrentIndex(index);
return true;
}
bool QPIConsole::renameTab(uint index, const QString & new_name) {
if (int(index) >= tabs.size()) return false;
if (tabs[index].name == new_name) return true;
setTabText(index, new_name);
tabs[index].name = new_name;
return true;
}
void QPIConsole::setTabEnabled(int index, bool on) {
if (int(index) >= tabs.size()) return;
if (isTabEnabled(index) == on) return;
QTabWidget::setTabEnabled(index, on);
}

View File

@@ -0,0 +1,187 @@
#ifndef QPICONSOLE_H
#define QPICONSOLE_H
#include <QTabWidget>
#include <QLabel>
#include <QBoxLayout>
#include <QFormLayout>
#include <QSpacerItem>
#include <QDebug>
typedef long long llong;
typedef unsigned char uchar;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ullong;
typedef long double ldouble;
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class 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
};
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);
void addVariable(const QString & name, const QString * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const char * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const bool * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const short * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const int * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const long * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const llong * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const uchar * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const ushort * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const uint * ptr, int column = 1, Formats format = QPIConsole::Normal);
void addVariable(const QString & name, const ulong * ptr, int column = 1, Formats format = QPIConsole::Normal);
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 addEmptyLine(int column = 1, uint count = 1);
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 renameTab(uint index, const QString & 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();}
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();}
private:
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;}
const QString & toBin(const void * d, int s);
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);
if (f.testFlag(QPIConsole::Oct)) return "0" + QString::number(v, 8);
if (f.testFlag(QPIConsole::Bin)) return toBin(&v, bits);
return QString::number(v);
}
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 Variable {
Variable() {label = widget = 0;}
QString name;
Formats format;
int type;
int bitFrom;
int bitCount;
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;}
};
struct Column {
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;}
};
struct Tab {
Tab(QString n = "", char k = 0) {columns.reserve(16); name = n; key = k;}
QVector<Column> columns;
QString name;
char key;
QHBoxLayout * layout;
QLabel * widget;
};
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;}
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QPIConsole::Formats)
QT_END_NAMESPACE
QT_END_HEADER
#endif // QPICONSOLE_H

View File

@@ -0,0 +1,34 @@
#include "qpointedit.h"
#include "float.h"
QPointEdit::QPointEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
s_x = new QDoubleSpinBox(this);
s_y = new QDoubleSpinBox(this);
s_x->setMinimum(-DBL_MAX);
s_x->setMaximum(DBL_MAX);
s_y->setMinimum(-DBL_MAX);
s_y->setMaximum(DBL_MAX);
s_x->setToolTip(tr("X"));
s_y->setToolTip(tr("Y"));
lbl = new QLabel(this);
lbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
lbl->setText("x");
lay.setContentsMargins(0, 0, 0, 0);
lay.setSpacing(1);
lay.addWidget(s_x);
lay.addWidget(lbl);
lay.addWidget(s_y);
connect(s_x, SIGNAL(valueChanged(double)), this, SLOT(changed()));
connect(s_y, SIGNAL(valueChanged(double)), this, SLOT(changed()));
}
void QPointEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
s_x->setToolTip(tr("X"));
s_y->setToolTip(tr("Y"));
return;
}
QWidget::changeEvent(e);
}

View File

@@ -0,0 +1,42 @@
#ifndef QPOINTEDIT_H
#define QPOINTEDIT_H
#include <QDoubleSpinBox>
#include <QBoxLayout>
#include <QLabel>
#include <QEvent>
class 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();}
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);}
private:
virtual void changeEvent(QEvent * e);
QBoxLayout lay;
QDoubleSpinBox * s_x, * s_y;
QLabel * lbl;
private slots:
void changed() {emit valueChanged(QPointF(s_x->value(), s_y->value()));}
signals:
void valueChanged(QPointF);
};
#endif // QPOINTEDIT_H

View File

@@ -0,0 +1,56 @@
#include "qrectedit.h"
#include "float.h"
QRectEdit::QRectEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
s_x = new QDoubleSpinBox(this);
s_y = new QDoubleSpinBox(this);
s_w = new QDoubleSpinBox(this);
s_h = new QDoubleSpinBox(this);
s_x->setMinimum(-DBL_MAX);
s_x->setMaximum(DBL_MAX);
s_y->setMinimum(-DBL_MAX);
s_y->setMaximum(DBL_MAX);
s_w->setMinimum(-DBL_MAX);
s_w->setMaximum(DBL_MAX);
s_h->setMinimum(-DBL_MAX);
s_h->setMaximum(DBL_MAX);
s_x->setToolTip(tr("X"));
s_y->setToolTip(tr("Y"));
s_w->setToolTip(tr("Height"));
s_h->setToolTip(tr("Width"));
lbl_0 = new QLabel(this);
lbl_0->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
lbl_0->setText("x");
lbl_1 = new QLabel(this);
lbl_1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
lbl_1->setText(";");
lbl_2 = new QLabel(this);
lbl_2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
lbl_2->setText("x");
lay.setContentsMargins(0, 0, 0, 0);
lay.setSpacing(1);
lay.addWidget(s_x);
lay.addWidget(lbl_0);
lay.addWidget(s_y);
lay.addWidget(lbl_1);
lay.addWidget(s_w);
lay.addWidget(lbl_2);
lay.addWidget(s_h);
connect(s_x, SIGNAL(valueChanged(double)), this, SLOT(changed()));
connect(s_y, SIGNAL(valueChanged(double)), this, SLOT(changed()));
connect(s_w, SIGNAL(valueChanged(double)), this, SLOT(changed()));
connect(s_h, SIGNAL(valueChanged(double)), this, SLOT(changed()));
}
void QRectEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
s_x->setToolTip(tr("X"));
s_y->setToolTip(tr("Y"));
s_w->setToolTip(tr("Height"));
s_h->setToolTip(tr("Width"));
return;
}
QWidget::changeEvent(e);
}

View File

@@ -0,0 +1,51 @@
#ifndef QRECTEDIT_H
#define QRECTEDIT_H
#include <QDoubleSpinBox>
#include <QBoxLayout>
#include <QLabel>
#include <QEvent>
class QRectEdit: public QWidget
{
Q_OBJECT
Q_PROPERTY(QRectF value READ value WRITE setValue)
Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
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();}
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);}
private:
virtual void changeEvent(QEvent * e);
QBoxLayout lay;
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()));}
signals:
void valueChanged(QRectF);
};
#endif // QRECTEDIT_H

View File

@@ -0,0 +1,490 @@
#include "qvariantedit.h"
#include <QDateTimeEdit>
#include <QFileDialog>
StringListEdit::~StringListEdit() {
delete combo;
delete butt_add;
delete butt_del;
delete butt_clear;
}
QStringList StringListEdit::value() const {
QStringList l;
for (int i = 0; i < combo->count(); ++i) l << combo->itemText(i);
return l;
}
void StringListEdit::setValue(const QStringList & v) {
combo->clear();
if (!v.isEmpty()) {
combo->addItems(v);
combo->setCurrentIndex(0);
}
}
void StringListEdit::addItem() {
combo->addItem(combo->currentText());
emit valueChanged();
}
void StringListEdit::delItem() {
if (combo->currentIndex() < 0) return;
combo->removeItem(combo->currentIndex());
emit valueChanged();
}
void StringListEdit::clear() {
if (combo->count() == 0) return;
combo->clear();
emit valueChanged();
}
StringListEdit::StringListEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
combo = new EComboBox(this);
combo->setEditable(true);
combo->setLineEdit(new CLineEdit);
combo->setInsertPolicy(QComboBox::NoInsert);
butt_add = new QPushButton(this);
butt_del = new QPushButton(this);
butt_clear = new QPushButton(this);
/*butt_add->setIconSize(QSize(16, 16));
butt_del->setIconSize(QSize(16, 16));
butt_clear->setIconSize(QSize(16, 16));*/
butt_add->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
butt_del->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
butt_clear->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
butt_add->setIcon(QIcon(":/icons/list-add.png"));
butt_del->setIcon(QIcon(":/icons/edit-delete.png"));
butt_clear->setIcon(QIcon(":/icons/edit-clear.png"));
butt_add->setToolTip(tr("Add"));
butt_del->setToolTip(tr("Remove"));
butt_clear->setToolTip(tr("Clear"));
lay.setContentsMargins(0, 0, 0, 0);
lay.setSpacing(2);
lay.addWidget(combo);
lay.addWidget(butt_add);
lay.addWidget(butt_del);
lay.addWidget(butt_clear);
connect(combo->lineEdit(), SIGNAL(returnPressed()), this, SLOT(editItem()));
connect(butt_add, SIGNAL(clicked(bool)), this, SLOT(addItem()));
connect(butt_del, SIGNAL(clicked(bool)), this, SLOT(delItem()));
connect(butt_clear, SIGNAL(clicked(bool)), this, SLOT(clear()));
}
void StringListEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
butt_add->setToolTip(tr("Add"));
butt_del->setToolTip(tr("Remove"));
butt_clear->setToolTip(tr("Clear"));
return;
}
QWidget::changeEvent(e);
}
void StringListEdit::editItem() {
int ci = combo->currentIndex();
if (ci < 0) return;
combo->setItemText(ci, combo->currentText());
}
PathEdit::PathEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
is_dir = is_abs = false;
filter = tr("All files(*)");
line = new CLineEdit(this);
//line->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
butt_select = new QPushButton(this);
//butt_select->setIconSize(QSize(16, 16));
butt_select->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
butt_select->setIcon(QIcon(":/icons/document-open.png"));
butt_select->setToolTip(tr("Choose") + " ...");
lay.setContentsMargins(0, 0, 0, 0);
//lay.setSpacing(2);
lay.addWidget(line);
lay.addWidget(butt_select);
connect(line, SIGNAL(textChanged(QString)), this, SIGNAL(valueChanged()));
connect(butt_select, SIGNAL(clicked(bool)), this, SLOT(select()));
}
void PathEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
butt_select->setToolTip(tr("Choose") + " ...");
return;
}
QWidget::changeEvent(e);
}
void PathEdit::resizeEvent(QResizeEvent *) {
butt_select->setMaximumHeight(line->height());
}
void PathEdit::select() {
QString ret;
if (is_dir) ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), value());
else ret = QFileDialog::getOpenFileName(this, tr("Select file"), value(), filter);
if (ret.isEmpty()) return;
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;
_recreate(QVariant());
}
QVariantEdit::~QVariantEdit() {
_delete();
}
void QVariantEdit::resizeEvent(QResizeEvent * e) {
//_resize();
QWidget::resizeEvent(e);
}
void QVariantEdit::_recreate(const QVariant & new_value) {
if (!new_value.isValid()) {
if (_cur_edit != _empty) _delete();
if (_empty == 0) {
_empty = new QLabel(trUtf8("Invalid value"), this);
_empty->setAlignment(Qt::AlignCenter);
_cur_edit = _empty;
_resize();
}
_value = new_value;
return;
}
if (_value.userType() == new_value.userType()) {
_value = new_value;
return;
}
_delete();
switch (new_value.type()) {
case QVariant::Bool:
_check = new QCheckBox(this);
_check->setAutoFillBackground(true);
_cur_edit = _check;
connect(_check, SIGNAL(toggled(bool)), this, SLOT(_changed()));
break;
case QVariant::Int:
_spin = new QDoubleSpinBox(this);
_spin->setDecimals(0);
_spin->setRange(-0x7FFFFFFF, 0x7FFFFFFF);
_cur_edit = _spin;
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
break;
case QVariant::UInt:
_spin = new QDoubleSpinBox(this);
_spin->setDecimals(0);
_spin->setRange(0, 0xFFFFFFFF);
_cur_edit = _spin;
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
break;
case QVariant::LongLong:
_spin = new QDoubleSpinBox(this);
_spin->setDecimals(0);
_spin->setRange(-0x7FFFFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFFFL);
_cur_edit = _spin;
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
break;
case QVariant::ULongLong:
_spin = new QDoubleSpinBox(this);
_spin->setDecimals(0);
_spin->setRange(0L, 0x7FFFFFFFFFFFFFFFL);
_cur_edit = _spin;
connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
break;
case QVariant::Double:
_espin = new EvalSpinBox(this);
//_spin->setDecimals(5);
//_spin->setRange(-1E+199, 1E+199);
_cur_edit = _espin;
connect(_espin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
break;
case QVariant::Color:
_color = new ColorButton(this);
_color->setUseAlphaChannel(true);
_cur_edit = _color;
connect(_color, SIGNAL(colorChanged(QColor)), this, SLOT(_changed()));
break;
case QVariant::String:
_line = new CLineEdit(this);
_cur_edit = _line;
connect(_line, SIGNAL(textChanged(QString)), this, SLOT(_changed()));
break;
case QVariant::StringList:
_list = new StringListEdit(this);
_cur_edit = _list;
connect(_list, SIGNAL(valueChanged()), this, SLOT(_changed()));
break;
case QVariant::Rect:
_rect = new QRectEdit(this);
_rect->setDecimals(0);
_cur_edit = _rect;
connect(_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(_changed()));
break;
case QVariant::RectF:
_rect = new QRectEdit(this);
_rect->setDecimals(3);
_cur_edit = _rect;
connect(_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(_changed()));
break;
case QVariant::Point:
_point = new QPointEdit(this);
_point->setDecimals(0);
_cur_edit = _point;
connect(_point, SIGNAL(valueChanged(QPointF)), this, SLOT(_changed()));
break;
case QVariant::PointF:
_point = new QPointEdit(this);
_point->setDecimals(3);
_cur_edit = _point;
connect(_point, SIGNAL(valueChanged(QPointF)), this, SLOT(_changed()));
break;
case QVariant::Date:
_date = new QDateEdit(this);
_cur_edit = _date;
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
break;
case QVariant::Time:
_date = new QTimeEdit(this);
_cur_edit = _date;
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
break;
case QVariant::DateTime:
_date = new QDateTimeEdit(this);
_cur_edit = _date;
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
break;
default: break;
}
if (!_cur_edit) {
if (new_value.canConvert<QAD::Enum>()) {
_enum = new EComboBox(this);
_setEnum(new_value.value<QAD::Enum>());
_cur_edit = _enum;
connect(_enum, SIGNAL(currentIndexChanged(int)), this, SLOT(_changed()));
}
if (new_value.canConvert<QAD::File>()) {
_path = new PathEdit(this);
_setFile(new_value.value<QAD::File>());
_cur_edit = _path;
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
}
if (new_value.canConvert<QAD::Dir>()) {
_path = new PathEdit(this);
_setDir(new_value.value<QAD::Dir>());
_cur_edit = _path;
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
}
if (!_cur_edit) { // try custom
QVariantEditorFactoryBase * f = QVariantEditorFactories::editorFactory(new_value.userType());
if (f) {
QWidget * fw = f->createEditor();
if (fw) {
fw->setParent(this);
_custom = fw;
_cur_edit = _custom;
connect(_custom, SIGNAL(valueChanged()), this, SLOT(_changed()));
}
}
}
}
//qDebug() << _cur_edit;
if (_cur_edit) {
_resize();
//_cur_edit->show();
}
_value = new_value;
}
QVariant QVariantEdit::value() const {
switch (_value.type()) {
case QVariant::Bool: return _check->isChecked();
case QVariant::Int: return int(_spin->value());
case QVariant::UInt: return (unsigned int)(_spin->value());
case QVariant::LongLong: return qlonglong(_spin->value());
case QVariant::ULongLong: return qulonglong(_spin->value());
case QVariant::Double: return _espin->value();
case QVariant::Color: return _color->color();
case QVariant::String: return _line->text();
case QVariant::StringList: return _list->value();
case QVariant::Rect: return _rect->value().toRect();
case QVariant::RectF: return _rect->value();
case QVariant::Point: return _point->value().toPoint();
case QVariant::PointF: return _point->value();
case QVariant::Date: return _date->date();
case QVariant::Time: return _date->time();
case QVariant::DateTime: return _date->dateTime();
default:
if (_value.canConvert<QAD::Enum>() && _enum) {
QAD::Enum ret;
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();
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;
return QVariant::fromValue<QAD::File>(ret);
}
}
if (_value.canConvert<QAD::Dir>() && _path) {
if (_path->is_dir) {
QAD::Dir ret;
ret.dir = _path->value();
ret.is_abs = _path->is_abs;
return QVariant::fromValue<QAD::Dir>(ret);
}
}
if (_custom) {
return _custom->property("value");
}
}
return QVariant();
}
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 (_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;
_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;
}
void QVariantEdit::_resize() {
if (!_cur_edit) return;
layout()->addWidget(_cur_edit);
}
void QVariantEdit::_newPath() {
_delete();
_path = new PathEdit(this);
_cur_edit = _path;
_value = _value.toString();
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
_resize();
//_cur_edit->show();
}
void QVariantEdit::_setEnum(const QAD::Enum & v) {
_enum->clear();
_enum->setProperty("enum_name", v.enum_name);
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)
if (_enum->itemText(i) == v.selected) {
_enum->setCurrentIndex(i);
break;
}
if (i == _enum->count())
_enum->setCurrentIndex(-1);
}
void QVariantEdit::_setFile(const QAD::File & v) {
_path->is_dir = false;
_path->setValue(v.file);
_path->filter = v.filter;
_path->is_abs = v.is_abs;
}
void QVariantEdit::_setDir(const QAD::Dir & v) {
_path->is_dir = true;
_path->setValue(v.dir);
_path->is_abs = v.is_abs;
}
void QVariantEdit::_setCustom(const QVariant & v) {
_custom->setProperty("value", v);
}
void QVariantEdit::_changed() {
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
emit valueChanged(value());
}

View File

@@ -0,0 +1,135 @@
#ifndef QVARIANTEDIT_H
#define QVARIANTEDIT_H
#include "qvariantedit_custom.h"
#include "qad_types.h"
#include "clineedit.h"
#include "ecombobox.h"
#include "colorbutton.h"
#include "qrectedit.h"
#include "qpointedit.h"
#include "evalspinbox.h"
#include <QCheckBox>
#include <QPushButton>
#include <QDoubleSpinBox>
class StringListEdit: public QWidget
{
Q_OBJECT
public:
StringListEdit(QWidget * parent = 0);
~StringListEdit();
QStringList value() const;
private:
virtual void changeEvent(QEvent * e);
QBoxLayout lay;
EComboBox * combo;
QPushButton * 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 PathEdit: public QWidget
{
Q_OBJECT
public:
PathEdit(QWidget * parent = 0);
~PathEdit() {delete line; delete butt_select;}
QString value() const {return line->text();}
bool is_dir, is_abs;
QString filter;
private:
virtual void changeEvent(QEvent * e);
virtual void resizeEvent(QResizeEvent * );
QBoxLayout lay;
CLineEdit * line;
QPushButton * butt_select;
public slots:
void setValue(const QString & v) {line->setText(v);}
private slots:
void select();
signals:
void valueChanged();
};
class 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();}
protected:
virtual void resizeEvent(QResizeEvent * );
void _recreate(const QVariant & new_value);
void _delete();
void _resize();
void _newPath();
void _setEnum(const QAD::Enum & v);
void _setFile(const QAD::File & v);
void _setDir(const QAD::Dir & v);
void _setCustom(const QVariant & v);
QLabel * _empty;
CLineEdit * _line;
QCheckBox * _check;
ColorButton * _color;
StringListEdit * _list;
QDateTimeEdit * _date;
QDoubleSpinBox * _spin;
EvalSpinBox * _espin;
QRectEdit * _rect;
QPointEdit * _point;
PathEdit * _path;
EComboBox * _enum;
QWidget * _custom, * _cur_edit;
QVariant _value;
private slots:
void _changed();
public slots:
void setValue(const QVariant & v);
signals:
void valueChanged(QVariant);
};
#endif // QVARIANTEDIT_H

View File

@@ -0,0 +1,43 @@
#include "qvariantedit_custom.h"
QVariantEditorFactories::QVariantEditorFactories() {
}
QVariantEditorFactories * QVariantEditorFactories::instance() {
static QVariantEditorFactories * ret = new QVariantEditorFactories();
return ret;
}
void QVariantEditorFactories::registerEditorFactory(int meta_id, QVariantEditorFactoryBase * f) {
QVariantEditorFactories * s = QVariantEditorFactories::instance();
if (!f) {
unregisterEditorFactory(meta_id);
return;
}
if (s->factories.contains(meta_id))
;//qDebug() << "[QVariantEditorFactories] Warning: factory for metaTypeID" << meta_id << "already registered, override";
s->factories[meta_id] = f;
}
void QVariantEditorFactories::unregisterEditorFactory(int meta_id) {
QVariantEditorFactories * s = QVariantEditorFactories::instance();
s->factories.remove(meta_id);
}
bool QVariantEditorFactories::isRegisteredEditorFactory(int meta_id) {
QVariantEditorFactories * s = QVariantEditorFactories::instance();
return s->factories.contains(meta_id);
}
QVariantEditorFactoryBase * QVariantEditorFactories::editorFactory(int meta_id) {
QVariantEditorFactories * s = QVariantEditorFactories::instance();
return s->factories.value(meta_id, 0);
}

View File

@@ -0,0 +1,36 @@
#ifndef QVARIANTEDIT_CUSTOM_H
#define QVARIANTEDIT_CUSTOM_H
#include <QDebug>
#include <QWidget>
#include <QMap>
class QVariantEdit;
class QVariantEditorFactoryBase {
friend class QVariantEdit;
public:
QVariantEditorFactoryBase() {}
virtual QWidget * createEditor() = 0;
private:
};
class QVariantEditorFactories {
public:
static void registerEditorFactory(int meta_id, QVariantEditorFactoryBase * f);
static void unregisterEditorFactory(int meta_id);
static bool isRegisteredEditorFactory(int meta_id);
static QVariantEditorFactoryBase * editorFactory(int meta_id);
private:
QVariantEditorFactories();
static QVariantEditorFactories * instance();
QMap<int, QVariantEditorFactoryBase * > factories;
};
#endif // QVARIANTEDIT_CUSTOM_H

View File

@@ -0,0 +1,236 @@
#include <QApplication>
#include <QFileInfo>
#include <QMetaMethod>
#include "session_manager.h"
void SessionManager::setFile(const QString & file) {
if (file.isEmpty()) {
file_.clear();
return;
}
QFileInfo fi(file);
if (fi.isAbsolute()) {
file_ = file;
return;
}
file_ = QApplication::applicationDirPath() + "/" + file;
}
void SessionManager::removeMainWidget(QWidget * e) {
for (int i = 0; i < widgets.size(); ++i) {
if (widgets[i].first == e->objectName()) {
widgets.remove(i);
--i;
}
}
}
void SessionManager::save() {
if (file_.isEmpty()) return;
QPIConfig sr(file_);
QObjectList tsc;
for (int i = 0; i < mwindows.size(); ++i) {
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 * > sp = mwindows[i].second->findChildren<QSplitter * >();
foreach (QSplitter * s, sp)
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 + " window state", (int)widgets[i].second->windowState(), false);
}
for (int i = 0; i < checks.size(); ++i)
sr.setValue(checks[i].first, checks[i].second->isChecked(), false);
for (int i = 0; i < lines.size(); ++i)
sr.setValue(lines[i].first, lines[i].second->text(), "s", false);
for (int i = 0; i < combos.size(); ++i)
sr.setValue(combos[i].first, combos[i].second->currentIndex(), false);
for (int i = 0; i < dspins.size(); ++i)
sr.setValue(dspins[i].first, dspins[i].second->value(), false);
for (int i = 0; i < spins.size(); ++i)
sr.setValue(spins[i].first, spins[i].second->value(), false);
for (int i = 0; i < spinsliders.size(); ++i)
sr.setValue(spinsliders[i].first, spinsliders[i].second->value(), false);
for (int i = 0; i < evals.size(); ++i)
sr.setValue(evals[i].first, evals[i].second->expression(), "s", false);
for (int i = 0; i < tabs.size(); ++i)
sr.setValue(tabs[i].first, tabs[i].second->currentIndex(), false);
for (int i = 0; i < buttons.size(); ++i)
sr.setValue(buttons[i].first, buttons[i].second->isChecked(), false);
for (int i = 0; i < stacks.size(); ++i)
sr.setValue(stacks[i].first, stacks[i].second->currentIndex(), false);
for (int i = 0; i < actions.size(); ++i)
sr.setValue(actions[i].first, actions[i].second->isChecked(), false);
for (int i = 0; i < stringlists.size(); ++i)
sr.setValue(stringlists[i].first, *stringlists[i].second, false);
for (int i = 0; i < strings.size(); ++i)
sr.setValue(strings[i].first, *strings[i].second, "s", false);
for (int i = 0; i < colors.size(); ++i)
sr.setValue(colors[i].first, *colors[i].second, false);
for (int i = 0; i < bools.size(); ++i)
sr.setValue(bools[i].first, *bools[i].second, false);
for (int i = 0; i < ints.size(); ++i)
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 |= QSet<QObject*>::fromList(c->findChildren<QObject*>());
}
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);
if (!mo || fn.isEmpty()) continue;
QByteArray value;
//qDebug() << "save" << o->objectName();
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray*, &value));
sr.setValue(o->objectName(), value, false);
}
//qDebug() << mcl.size();
emit saving(sr);
sr.writeAll();
}
void SessionManager::load(bool onlyMainwindow) {
if (file_.isEmpty()) return;
QPIConfig sr(file_);
QObjectList tsc;
for (int i = 0; i < mwindows.size(); ++i) {
tsc << mwindows[i].second;
mwindows[i].second->restoreState(sr.getValue(mwindows[i].first + " state", QByteArray()));
mwindows[i].second->restoreGeometry(sr.getValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), QByteArray()));
mwindows[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(mwindows[i].first + " window state", 0));
QList<QSplitter * > sp = mwindows[i].second->findChildren<QSplitter * >();
foreach (QSplitter * s, sp)
s->restoreState(sr.getValue(mwindows[i].first + " splitter " + s->objectName(), QByteArray()));
}
for (int i = 0; i < widgets.size(); ++i) {
tsc << widgets[i].second;
widgets[i].second->restoreGeometry(sr.getValue(widgets[i].first + " geometry " + QString::number((int)widgets[i].second->windowState()), QByteArray()));
widgets[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(widgets[i].first + " window state", 0));
}
if (onlyMainwindow) return;
for (int i = 0; i < checks.size(); ++i)
checks[i].second->setChecked(sr.getValue(checks[i].first, checks[i].second->isChecked()));
for (int i = 0; i < lines.size(); ++i)
lines[i].second->setText(sr.getValue(lines[i].first, lines[i].second->text()));
for (int i = 0; i < combos.size(); ++i) {
QComboBox * c = combos[i].second;
int v = sr.getValue(combos[i].first, c->currentIndex());
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()));
for (int i = 0; i < spins.size(); ++i)
spins[i].second->setValue(sr.getValue(spins[i].first, spins[i].second->value()));
for (int i = 0; i < spinsliders.size(); ++i)
spinsliders[i].second->setValue(sr.getValue(spinsliders[i].first, spinsliders[i].second->value()));
for (int i = 0; i < evals.size(); ++i)
evals[i].second->setExpression(sr.getValue(evals[i].first, evals[i].second->expression()));
for (int i = 0; i < tabs.size(); ++i) {
QTabWidget * t = tabs[i].second;
int v = sr.getValue(tabs[i].first, t->currentIndex());
if (v >= 0 && v < t->count())
t->setCurrentIndex(v);
}
for (int i = 0; i < buttons.size(); ++i)
buttons[i].second->setChecked(sr.getValue(buttons[i].first, buttons[i].second->isChecked()));
for (int i = 0; i < stacks.size(); ++i)
stacks[i].second->setCurrentIndex(qMin((int)sr.getValue(stacks[i].first, stacks[i].second->currentIndex()), 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()));
for (int i = 0; i < stringlists.size(); ++i)
*stringlists[i].second = sr.getValue(stringlists[i].first, *stringlists[i].second);
for (int i = 0; i < strings.size(); ++i)
*strings[i].second = sr.getValue(strings[i].first, *strings[i].second).stringValue();
for (int i = 0; i < colors.size(); ++i)
*colors[i].second = sr.getValue(colors[i].first, *colors[i].second);
for (int i = 0; i < bools.size(); ++i)
*bools[i].second = sr.getValue(bools[i].first, *bools[i].second);
for (int i = 0; i < ints.size(); ++i)
*ints[i].second = sr.getValue(ints[i].first, *ints[i].second);
for (int i = 0; i < floats.size(); ++i)
*floats[i].second = sr.getValue(floats[i].first, *floats[i].second);
QSet<QObject*> all_list;
foreach (QObject * c, tsc) {
all_list |= QSet<QObject*>::fromList(c->findChildren<QObject*>());
}
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);
if (!mo || fn.isEmpty()) continue;
QByteArray value = sr.getValue(o->objectName(), QByteArray());
//qDebug() << "load" << o->objectName();
mo->invokeMethod(o, fn.constData(), Q_ARG(QByteArray*, &value));
}
emit loading(sr);
}
void SessionManager::clear(bool with_filename) {
mwindows.clear();
widgets.clear();
checks.clear();
lines.clear();
combos.clear();
dspins.clear();
spins.clear();
spinsliders.clear();
evals.clear();
tabs.clear();
buttons.clear();
stacks.clear();
actions.clear();
stringlists.clear();
strings.clear();
colors.clear();
bools.clear();
ints.clear();
floats.clear();
if (with_filename) setFile("");
}
QMap<const QMetaObject *, QByteArray> SessionManager::metaFunctions(const QSet<QObject *> & objects, QByteArray fname) {
QMap<const QMetaObject*, QByteArray> funcs;
foreach (QObject * o, objects) {
const QMetaObject * mo = o->metaObject();
if (!mo) continue;
QByteArray fn;
if (!funcs.contains(mo)) {
for (int i = 0; i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
QByteArray mmn =
#if QT_VERSION >= 0x050000
mm.name();
#else
mm.signature();
mmn = mmn.left(mmn.indexOf('('));
#endif
if (mmn == fname) {
if (mm.parameterTypes().size() > 0) {
if (mm.parameterTypes()[0] == "QByteArray*") {
fn = mmn;
}
}
}
}
funcs[mo] = fn;
} else fn = funcs[mo];
}
return funcs;
}

View File

@@ -0,0 +1,104 @@
#ifndef SESSION_MANAGER_H
#define SESSION_MANAGER_H
#include <QPair>
#include <QMainWindow>
#include <QCheckBox>
#include <QLineEdit>
#include <QDoubleSpinBox>
#include <QAction>
#include <QComboBox>
#include <QTabWidget>
#include <QToolButton>
#include <QSplitter>
#include <QStackedWidget>
#include "spinslider.h"
#include "evalspinbox.h"
#include "qpiconfig.h"
/// for all children widgets of "QMainWindow"s and MainWidgets
/// check for slots
/// * void sessionSave(QByteArray * data);
/// * void sessionLoad(QByteArray * data);
class SessionManager: public QObject
{
Q_OBJECT
public:
SessionManager(const QString & file = QString()) {setFile(file);}
~SessionManager() {;}
void setFile(const QString & file);
void addEntry(QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(e->objectName(), e));}
void addEntry(QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(e->objectName(), e));}
void addEntry(QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(e->objectName(), e));}
void addEntry(QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(e->objectName(), e));}
void addEntry(QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(e->objectName(), e));}
void addEntry(QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(e->objectName(), e));}
void addEntry(SpinSlider * e) {spinsliders.push_back(QPair<QString, SpinSlider * >(e->objectName(), e));}
void addEntry(EvalSpinBox * e) {evals.push_back(QPair<QString, EvalSpinBox * >(e->objectName(), e));}
void addEntry(QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(e->objectName(), e));}
void addEntry(QAction * e) {actions.push_back(QPair<QString, QAction * >(e->objectName(), e));}
void addEntry(QAbstractButton * e) {buttons.push_back(QPair<QString, QAbstractButton * >(e->objectName(), e));}
void addEntry(QStackedWidget * e) {stacks.push_back(QPair<QString, QStackedWidget * >(e->objectName(), e));}
void addMainWidget(QWidget * e) {widgets.push_back(QPair<QString, QWidget * >(e->objectName(), e));}
void removeMainWidget(QWidget * e);
void addEntry(const QString & name, QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(name, 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, 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);
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, 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;
QString file_;
public slots:
void save();
void load(bool onlyMainwindow = false);
void clear(bool with_filename = true);
signals:
void loading(QPIConfig & );
void saving(QPIConfig & );
};
#endif // SESSION_MANAGER_H

View File

@@ -0,0 +1,233 @@
#include "shortcuts.h"
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());
}
Shortcuts::Shortcuts(QWidget * parent, bool on): QTreeWidget(parent) {
aw = 0;
QImage ti(QSize(16, 16), QImage::Format_ARGB32_Premultiplied);
QPainter p(&ti);
p.setCompositionMode(QPainter::CompositionMode_Clear);
p.eraseRect(ti.rect());
p.end();
empty_icon = QPixmap::fromImage(ti);
bfont = font();
bfont.setWeight(QFont::Bold);
active = on;
setColumnCount(2);
#if QT_VERSION < 0x050000
header()->setResizeMode(0, QHeaderView::ResizeToContents);
header()->setResizeMode(1, QHeaderView::ResizeToContents);
#else
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
#endif
header()->setStretchLastSection(true);
setColumnWidth(1, 200);
setSortingEnabled(true);
QStringList l;
l << tr("Command") << tr("Shortcut");
setHeaderLabels(l);
assignWindow(parent);
}
Shortcuts::~Shortcuts() {
foreach (ShortcutEdit * i, edits)
delete i;
edits.clear();
}
void Shortcuts::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
QStringList l;
l << tr("Command") << tr("Shortcut");
setHeaderLabels(l);
}
}
void Shortcuts::assignWindow(QWidget * w) {
if (w == 0) return;
while ((qobject_cast<QMainWindow * >(w) == 0) && (w->parentWidget() != 0))
w = w->parentWidget();
aw = qobject_cast<QMainWindow * >(w);
updateShortcuts();
}
QStringList Shortcuts::actionTree(QAction * a) {
QStringList tree;
QList<QWidget * > aw = a->associatedWidgets();
if (aw.size() == 0) return tree;
QWidget * cw = 0;
QMenu * tm;
QToolBar * tt;
foreach (QWidget * i, aw) {
tm = qobject_cast<QMenu * >(i);
if (tm == 0) continue;
cw = i;
while (cw != 0) {
tm = qobject_cast<QMenu * >(cw);
if (tm != 0) {
if (!tm->title().isEmpty())
tree.push_front(tm->title());
cw = cw->parentWidget();
} else break;
}
if (!tree.isEmpty()) return tree;
}
foreach (QWidget * i, aw) {
tt = qobject_cast<QToolBar * >(i);
if (tt == 0) continue;
cw = i;
if (!tt->windowTitle().isEmpty())
tree.push_front(tt->windowTitle());
break;
}
return tree;
}
QList<QPair<QString, QKeySequence> > Shortcuts::shortcuts() {
QList<QPair<QString, QKeySequence> > l;
foreach (ShortcutEdit * i, edits) {
if (i->action()->objectName().isEmpty()) continue;
l << QPair<QString, QKeySequence>(i->action()->objectName(), i->text());
}
return l;
}
void Shortcuts::clear() {
foreach (ShortcutEdit * i, edits)
delete i;
edits.clear();
hide();
QList<QTreeWidgetItem * > tl = findItems("", Qt::MatchContains);
foreach (QTreeWidgetItem * i, tl)
delete i;
show();
}
bool Shortcuts::checkAction(QAction * a) {
if (a->menu() != 0) return false;
if (a->isSeparator()) return false;
if (a->text().isEmpty()) return false;
if (a->associatedWidgets().isEmpty()) return false;
if (QString(a->metaObject()->className()) != "QAction") return false;
if (qobject_cast<QWidgetAction * >(a) != 0) return false;
return true;
}
void Shortcuts::updateShortcuts() {
//return;
if (aw == 0 || !active) return;
hide();
int cpos = verticalScrollBar()->value();
clear();
#if QT_VERSION < 0x050000
header()->setResizeMode(0, QHeaderView::Fixed);
#else
header()->setSectionResizeMode(0, QHeaderView::Fixed);
#endif
QList<QAction * > al = aw->findChildren<QAction * >();
QTreeWidgetItem * pi, * ci;
QStringList tree;
bool s = isSortingEnabled(), isFound;
setSortingEnabled(false);
foreach (QAction * i, al) {
if (!checkAction(i)) continue;
edits.push_back(new ShortcutEdit());
tree = actionTree(i);
pi = invisibleRootItem();
foreach (QString t, tree) {
isFound = false;
for (int j = 0; j < pi->childCount(); ++j) {
if (pi->child(j)->text(0) == t) {
pi = pi->child(j);
isFound = true;
break;
}
}
if (isFound) continue;
ci = new QTreeWidgetItem(pi);
ci->setText(0, t);
ci->setToolTip(0, t);
ci->setFont(0, bfont);
pi->addChild(ci);
pi = ci;
}
ci = new QTreeWidgetItem(pi);
ci->setText(0, i->text());
ci->setToolTip(0, i->text());
if (i->icon().isNull())
ci->setIcon(0, empty_icon);
else
ci->setIcon(0, i->icon());
edits.back()->ti = ci;
edits.back()->assignAction(i);
pi->addChild(ci);
//qDebug() << "set widget" << edits.back();
setItemWidget(ci, 1, edits.back());
}
setSortingEnabled(s);
#if QT_VERSION < 0x050000
header()->setResizeMode(0, QHeaderView::ResizeToContents);
#else
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
#endif
expandAll();
verticalScrollBar()->setValue(cpos);
show();
}
void Shortcuts::commit() {
foreach (ShortcutEdit * i, edits)
i->commit();
}
void Shortcuts::reset() {
foreach (ShortcutEdit * i, edits)
i->reset();
updateShortcuts();
}
void Shortcuts::filter(const QString & what) {
hide();
for (int i = 0; i < topLevelItemCount(); ++i)
filterTree(topLevelItem(i), what);
show();
}
bool Shortcuts::filterTree(QTreeWidgetItem * ti, QString f) {
if (f.isEmpty()) {
for (int i = 0; i < ti->childCount(); ++i)
filterTree(ti->child(i), f);
ti->setHidden(false);
return true;
}
bool isFound = false;
for (int i = 0; i < ti->childCount(); ++i)
if (filterTree(ti->child(i), f)) isFound = true;
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;
}

View File

@@ -0,0 +1,90 @@
#ifndef SHORTCUTS_H
#define SHORTCUTS_H
#include <QTreeWidget>
#include <QMainWindow>
#include <QShortcut>
#include <QHeaderView>
#include <QAction>
#include <QLineEdit>
#include <QDebug>
#include <QKeyEvent>
#include <QMenu>
#include <QToolBar>
#include <QScrollBar>
#include <QWidgetAction>
#include "clineedit.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class ShortcutEdit: public CLineEdit
{
Q_OBJECT
friend class Shortcuts;
public:
explicit ShortcutEdit(QWidget * parent = 0): CLineEdit(parent) {ti = 0; ca = 0; connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));}
void assignAction(QAction * a) {clear(); ca = a; reset();}
QAction * action() const {return ca;}
bool isEmpty() const {return text().isEmpty();}
void commit() {if (ca == 0) return; ca->setShortcut(QKeySequence(text()));}
void reset() {if (ca == 0) return; setText(ca->shortcut().toString());}
private slots:
void textChanged_(QString t) {if (ti != 0) ti->setText(1, t);}
private:
void keyPressEvent(QKeyEvent * e);
QAction * ca;
QTreeWidgetItem * ti;
};
class Shortcuts: public QTreeWidget
{
Q_OBJECT
public:
explicit Shortcuts(QWidget * parent = 0, bool on = true);
~Shortcuts();
void assignWindow(QWidget * w);
void setActive(bool on) {active = on;}
QList<QPair<QString, QKeySequence> > shortcuts();
QStringList actionTree(QAction * a);
static bool checkAction(QAction * a);
public slots:
void clear();
void updateShortcuts();
void commit();
void reset();
void filter(const QString & what);
private:
virtual void updateEditorGeometries() {foreach (ShortcutEdit * i, edits) i->setGeometry(visualRect(indexFromItem(i->ti, 1)));}
virtual void changeEvent(QEvent * );
bool filterTree(QTreeWidgetItem * ti, QString f);
QMainWindow * aw;
QVector<ShortcutEdit * > edits;
QIcon empty_icon;
QFont bfont;
bool active;
private slots:
signals:
void shortcutChanged(QAction * , QShortcut & );
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // SPINSLIDER_H

View File

@@ -0,0 +1,85 @@
#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();
slider->setOrientation(Qt::Horizontal);
slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
spin = new QDoubleSpinBox();
adjust();
layout = new QBoxLayout(QBoxLayout::LeftToRight);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(slider);
layout->addWidget(spin);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)));
connect(spin, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double)));
setLayout(layout);
}
SpinSlider::~SpinSlider() {
delete spin;
delete slider;
delete layout;
}
void SpinSlider::setOrientation(Qt::Orientation orient) {
slider->setOrientation(orient);
if (orient == Qt::Horizontal)
slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
else
slider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
}
void SpinSlider::adjust() {
adjusting = true;
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 (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));
slider->setPageStep(qRound(page * delim));
slider->setTickInterval(qRound(ticks_ * delim));
emit valueChanged(val_);
emit valueChanged(qRound(val_));
adjusting = false;
}
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);
val_ = spin->value();
emit valueChanged(val_);
emit valueChanged(qRound(val_));
adjusting = false;
}
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));
emit valueChanged(val_);
emit valueChanged(qRound(val_));
adjusting = false;
}

View File

@@ -0,0 +1,102 @@
#ifndef SPINSLIDER_H
#define SPINSLIDER_H
#include <QSlider>
#include <QDoubleSpinBox>
#include <QBoxLayout>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class SpinSlider: public QWidget
{
Q_OBJECT
Q_ENUMS(Direction)
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
Q_PROPERTY(double value READ value WRITE setValue)
Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep)
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
Q_PROPERTY(QSlider::TickPosition tickPosition READ tickPosition WRITE setTickPosition)
Q_PROPERTY(int tickInterval READ tickInterval WRITE setTickInterval)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance)
Q_PROPERTY(bool squareScale READ squareScale WRITE setSquareScale)
Q_PROPERTY(double spinMinimum READ spinMinimum WRITE setSpinMinimum)
Q_PROPERTY(double spinMaximum READ spinMaximum WRITE setSpinMaximum)
public:
explicit SpinSlider(QWidget * parent = 0);
~SpinSlider();
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 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 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();}
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.);}
private:
void adjust();
double sqr(const double & v) {return v * v;}
double min_, max_, val_, delim, page;
int dec_, ticks_;
bool adjusting, square;
QSlider * slider;
QDoubleSpinBox * spin;
QBoxLayout * layout;
Direction direc;
private slots:
void sliderChanged(int value);
void spinChanged(double value);
signals:
void valueChanged(double);
void valueChanged(int);
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // SPINSLIDER_H