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

This commit is contained in:
2017-05-12 12:10:48 +00:00
parent d5218d7c4a
commit e6112cdb96
337 changed files with 26799 additions and 251 deletions

View File

@@ -0,0 +1,2 @@
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} qad_utils)
qad_project(widgets "${LIBS}")

151
qad/widgets/chardialog.cpp Normal file
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();
}

50
qad/widgets/chardialog.h Normal file
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

92
qad/widgets/chardialog.ui Normal file
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>

51
qad/widgets/clineedit.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include "clineedit.h"
CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
cw = new QWidget(this);
cw->setStyleSheet("background-image: url(:/icons/edit-clear-locationbar-rtl.png);");
cw->setCursor(Qt::ArrowCursor);
cw->setToolTip(tr("Clear"));
cw->hide();
cw->installEventFilter(this);
int m0, m1, m2, m3;
getTextMargins(&m0, &m1, &m2, &m3);
setTextMargins(m0, m1, m2 + 21, m3);
connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
//connect(cw, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(clearMouseRelease(QMouseEvent * )));
}
bool CLineEdit::eventFilter(QObject * o, QEvent * e) {
if (e->type() == QEvent::MouseButtonRelease) {
clearMouseRelease((QMouseEvent * )e);
}
return QLineEdit::eventFilter(o, e);
}
void CLineEdit::resizeEvent(QResizeEvent * e) {
QLineEdit::resizeEvent(e);
cw->setGeometry(width() - 21, (height() - 17) / 2, 16, 16);
}
void CLineEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
cw->setToolTip(tr("Clear"));
return;
}
QLineEdit::changeEvent(e);
}
void CLineEdit::setDefaultText(const QString & t, bool set_text) {
dt = t;
if (set_text) {
setText(t);
emit textEdited(t);
cw->hide();
return;
}
textChanged_(text());
}

43
qad/widgets/clineedit.h Normal file
View File

@@ -0,0 +1,43 @@
#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;}
inline QString defaultText() const {return dt;}
protected:
QWidget * cw;
QString dt;
private:
bool eventFilter(QObject * o, QEvent * e);
void resizeEvent(QResizeEvent * );
void changeEvent(QEvent * e);
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

112
qad/widgets/colorbutton.cpp Normal file
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());
}

63
qad/widgets/colorbutton.h Normal file
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

99
qad/widgets/ecombobox.cpp Normal file
View File

@@ -0,0 +1,99 @@
#include <QStandardItemModel>
#include <QApplication>
#include <QDebug>
#include <QHeaderView>
#include "ecombobox.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"));
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);
}

36
qad/widgets/ecombobox.h Normal file
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

68
qad/widgets/iconedlabel.h Normal file
View File

@@ -0,0 +1,68 @@
#ifndef ICONEDLABEL_H
#define ICONEDLABEL_H
#include <QLabel>
#include <QIcon>
#include <QHBoxLayout>
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): QFrame(parent) {
label_.setAlignment(Qt::AlignCenter);
icon_.setAlignment(Qt::AlignCenter);
size_ = QSize(16, 16);
setDirection(LeftToRight);
}
QString text() const {return label_.text();}
QIcon icon() const {return icon_.pixmap() == 0 ? QIcon() : QIcon(*icon_.pixmap());}
QSize iconSize() const {return size_;}
Direction direction() const {return dir_;}
protected:
QLabel label_;
QLabel icon_;
QIcon sicon_;
QSize size_;
Direction dir_;
public slots:
void setText(const QString & t) {label_.setText(t);}
void setIcon(const QIcon & i) {sicon_ = i; icon_.setPixmap(i.pixmap(size_));}
void setIconSize(const QSize & s) {size_ = s; icon_.setPixmap(sicon_.pixmap(size_));}
void setDirection(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();
}
signals:
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // ICONEDLABEL_H

Binary file not shown.

View File

@@ -0,0 +1,853 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="ru_RU">
<context>
<name>CLineEdit</name>
<message>
<location filename="../clineedit.cpp" line="8"/>
<location filename="../clineedit.cpp" line="23"/>
<source>Clear</source>
<translation>Сбросить</translation>
</message>
</context>
<context>
<name>CharDialog</name>
<message>
<location filename="../chardialog.ui" line="14"/>
<source>Choose symbol</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>No Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark NonSpacing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark SpacingCombining</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark Enclosing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number DecimalDigit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number Letter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Separator Space</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Separator Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Separator Paragraph</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Other Control</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Other Format</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other Surrogate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other PrivateUse</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other NotAssigned</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Letter Uppercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Lowercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Titlecase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Connector</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Dash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation InitialQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation FinalQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Symbol Math</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Currency</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Other</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ColorButton</name>
<message>
<location filename="../colorbutton.cpp" line="17"/>
<source>Copy</source>
<translation>Копировать</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="18"/>
<source>Paste</source>
<translation>Вставить</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="20"/>
<source>Mix with clipboard</source>
<translation>Смешать с буфером обмена</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="87"/>
<source>Choose color</source>
<translation>Выберите цвет</translation>
</message>
</context>
<context>
<name>EComboBox</name>
<message>
<location filename="../ecombobox.cpp" line="17"/>
<source>Filter</source>
<translation>Фильтр</translation>
</message>
</context>
<context>
<name>Graphic</name>
<message>
<location filename="../graphic.ui" line="44"/>
<source>Autofit</source>
<translation>Вписать</translation>
</message>
<message>
<location filename="../graphic.ui" line="61"/>
<source>Grid</source>
<translation>Сетка</translation>
</message>
<message>
<location filename="../graphic.ui" line="84"/>
<source>Cursor axis</source>
<translation>Координаты курсора</translation>
</message>
<message>
<location filename="../graphic.ui" line="104"/>
<source>Only expand Y</source>
<translation>Только расширять по Y</translation>
</message>
<message>
<location filename="../graphic.ui" line="124"/>
<source>Only expand X</source>
<translation>Только расширять по X</translation>
</message>
<message>
<location filename="../graphic.ui" line="144"/>
<source>Border inputs</source>
<translation>Граничные поля ввода</translation>
</message>
<message>
<location filename="../graphic.ui" line="167"/>
<source>Legend</source>
<translation>Легенда</translation>
</message>
<message>
<location filename="../graphic.ui" line="190"/>
<source>Configure ...</source>
<translation>Настроить ...</translation>
</message>
<message>
<location filename="../graphic.ui" line="207"/>
<source>Save image ...</source>
<translation>Сохранить изображение ...</translation>
</message>
<message>
<location filename="../graphic.ui" line="240"/>
<source>Clear</source>
<translation>Очистить</translation>
</message>
<message>
<location filename="../graphic.ui" line="257"/>
<source>Close</source>
<translation>Закрыть</translation>
</message>
<message>
<location filename="../graphic.ui" line="408"/>
<source>Cursor: ( ; )</source>
<translation>Курсор: ( ; )</translation>
</message>
<message>
<location filename="../graphic.cpp" line="196"/>
<location filename="../graphic.cpp" line="763"/>
<source>Cursor: </source>
<translation>Курсор: </translation>
</message>
<message>
<location filename="../graphic.cpp" line="206"/>
<source>Selection</source>
<translation>Выбрано</translation>
</message>
<message>
<location filename="../graphic.cpp" line="207"/>
<source>Size</source>
<translation>Размер</translation>
</message>
<message>
<location filename="../graphic.cpp" line="211"/>
<location filename="../graphic.cpp" line="217"/>
<source>Range</source>
<translation>Диапазон</translation>
</message>
<message>
<location filename="../graphic.cpp" line="212"/>
<location filename="../graphic.cpp" line="218"/>
<source>Length</source>
<translation>Длина</translation>
</message>
<message>
<location filename="../graphic.cpp" line="316"/>
<location filename="../graphic.cpp" line="346"/>
<source>Cursor</source>
<translation>Курсор</translation>
</message>
<message>
<location filename="../graphic.cpp" line="487"/>
<source>Save Image</source>
<translation>Соханение изображения</translation>
</message>
<message>
<location filename="../graphic.cpp" line="532"/>
<source>y(x)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphic.cpp" line="1075"/>
<source>Check all</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GraphicConf</name>
<message>
<location filename="../graphic_conf.ui" line="17"/>
<source>Graphic parameters</source>
<translation>Параметры графика</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="32"/>
<source>Appearance</source>
<translation>Внешний вид</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="46"/>
<source>Border inputs</source>
<translation>Граничные поля ввода</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="53"/>
<source>Antialiasing</source>
<translation>Антиалиасинг</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="60"/>
<source>Status bar</source>
<translation>Строка состояния</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="67"/>
<source>OpenGL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="74"/>
<source>Legend</source>
<translation>Легенда</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="94"/>
<source>Background color:</source>
<translation>Цвет фона:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="114"/>
<source>Text color:</source>
<translation>Цвет текста:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="245"/>
<source>Grid</source>
<translation>Сетка</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="380"/>
<source>Margins</source>
<translation>Отступы</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="392"/>
<location filename="../graphic_conf.ui" line="402"/>
<location filename="../graphic_conf.ui" line="422"/>
<location filename="../graphic_conf.ui" line="462"/>
<location filename="../graphic_conf.ui" line="482"/>
<source> px</source>
<translation> пикс</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="412"/>
<source>All:</source>
<translation>Все:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="432"/>
<source>Right:</source>
<translation>Правый:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="442"/>
<source>Left:</source>
<translation>Левый:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="452"/>
<source>Bottom:</source>
<translation>Нижний:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="472"/>
<source>Top:</source>
<translation>Верхний:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="161"/>
<location filename="../graphic_conf.ui" line="263"/>
<source>Color:</source>
<translation>Цвет:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="175"/>
<location filename="../graphic_conf.ui" line="277"/>
<source>Style:</source>
<translation>Стиль:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="287"/>
<source>Width:</source>
<translation>Толщина:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="317"/>
<source>Step X:</source>
<translation>Шаг X:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="324"/>
<source>Step Y:</source>
<translation>Шаг Y:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="347"/>
<source>Auto step</source>
<translation>Автоматическая</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="133"/>
<source>Graphics</source>
<translation>Графики</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="185"/>
<source>Lines width:</source>
<translation>Толщина линий:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="205"/>
<source>Points width:</source>
<translation>Толщина точек:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="225"/>
<source>Fill:</source>
<translation>Заливка:</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>NoPen</source>
<translation>Без линий</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>Solid</source>
<translation>Сплошная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>Dash</source>
<translation>Штриховая</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dot</source>
<translation>Пунктирная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dash-Dot</source>
<translation>Штрих-пунктирная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dash-Dot-Dot</source>
<translation>Штрих-пунктир-пунктирная</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 type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Value</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Comment</source>
<translation type="unfinished"></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 type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="361"/>
<source>Expand all</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="362"/>
<source>Collapse all</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QPointEdit</name>
<message>
<location filename="../qpointedit.cpp" line="11"/>
<location filename="../qpointedit.cpp" line="28"/>
<source>X</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpointedit.cpp" line="12"/>
<location filename="../qpointedit.cpp" line="29"/>
<source>Y</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QRectEdit</name>
<message>
<location filename="../qrectedit.cpp" line="17"/>
<location filename="../qrectedit.cpp" line="48"/>
<source>X</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="18"/>
<location filename="../qrectedit.cpp" line="49"/>
<source>Y</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="19"/>
<location filename="../qrectedit.cpp" line="50"/>
<source>Height</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="20"/>
<location filename="../qrectedit.cpp" line="51"/>
<source>Width</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Shortcuts</name>
<message>
<location filename="../shortcuts.cpp" line="33"/>
<location filename="../shortcuts.cpp" line="49"/>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../shortcuts.cpp" line="33"/>
<location filename="../shortcuts.cpp" line="49"/>
<source>Shortcut</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StringListEdit</name>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="20"/>
<location filename="../qpiconfigvaluewidget.cpp" line="37"/>
<source>Add</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="21"/>
<location filename="../qpiconfigvaluewidget.cpp" line="38"/>
<source>Remove</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="22"/>
<location filename="../qpiconfigvaluewidget.cpp" line="39"/>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

BIN
qad/widgets/lang/ru.qm Normal file

Binary file not shown.

853
qad/widgets/lang/ru.ts Normal file
View File

@@ -0,0 +1,853 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="ru_RU">
<context>
<name>CLineEdit</name>
<message>
<location filename="../clineedit.cpp" line="8"/>
<location filename="../clineedit.cpp" line="23"/>
<source>Clear</source>
<translation>Сбросить</translation>
</message>
</context>
<context>
<name>CharDialog</name>
<message>
<location filename="../chardialog.ui" line="14"/>
<source>Choose symbol</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>No Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark NonSpacing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark SpacingCombining</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="21"/>
<location filename="../chardialog.cpp" line="40"/>
<source>Mark Enclosing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number DecimalDigit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number Letter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Number Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="22"/>
<location filename="../chardialog.cpp" line="41"/>
<source>Separator Space</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Separator Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Separator Paragraph</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Other Control</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="23"/>
<location filename="../chardialog.cpp" line="42"/>
<source>Other Format</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other Surrogate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other PrivateUse</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Other NotAssigned</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="24"/>
<location filename="../chardialog.cpp" line="43"/>
<source>Letter Uppercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Lowercase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Titlecase</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="25"/>
<location filename="../chardialog.cpp" line="44"/>
<source>Letter Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Connector</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Dash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="26"/>
<location filename="../chardialog.cpp" line="45"/>
<source>Punctuation Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation InitialQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation FinalQuote</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Punctuation Other</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="27"/>
<location filename="../chardialog.cpp" line="46"/>
<source>Symbol Math</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Currency</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Modifier</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../chardialog.cpp" line="28"/>
<location filename="../chardialog.cpp" line="47"/>
<source>Symbol Other</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ColorButton</name>
<message>
<location filename="../colorbutton.cpp" line="17"/>
<source>Copy</source>
<translation>Копировать</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="18"/>
<source>Paste</source>
<translation>Вставить</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="20"/>
<source>Mix with clipboard</source>
<translation>Смешать с буфером обмена</translation>
</message>
<message>
<location filename="../colorbutton.cpp" line="87"/>
<source>Choose color</source>
<translation>Выберите цвет</translation>
</message>
</context>
<context>
<name>EComboBox</name>
<message>
<location filename="../ecombobox.cpp" line="17"/>
<source>Filter</source>
<translation>Фильтр</translation>
</message>
</context>
<context>
<name>Graphic</name>
<message>
<location filename="../graphic.ui" line="44"/>
<source>Autofit</source>
<translation>Вписать</translation>
</message>
<message>
<location filename="../graphic.ui" line="61"/>
<source>Grid</source>
<translation>Сетка</translation>
</message>
<message>
<location filename="../graphic.ui" line="84"/>
<source>Cursor axis</source>
<translation>Координаты курсора</translation>
</message>
<message>
<location filename="../graphic.ui" line="104"/>
<source>Only expand Y</source>
<translation>Только расширять по Y</translation>
</message>
<message>
<location filename="../graphic.ui" line="124"/>
<source>Only expand X</source>
<translation>Только расширять по X</translation>
</message>
<message>
<location filename="../graphic.ui" line="144"/>
<source>Border inputs</source>
<translation>Граничные поля ввода</translation>
</message>
<message>
<location filename="../graphic.ui" line="167"/>
<source>Legend</source>
<translation>Легенда</translation>
</message>
<message>
<location filename="../graphic.ui" line="190"/>
<source>Configure ...</source>
<translation>Настроить ...</translation>
</message>
<message>
<location filename="../graphic.ui" line="207"/>
<source>Save image ...</source>
<translation>Сохранить изображение ...</translation>
</message>
<message>
<location filename="../graphic.ui" line="240"/>
<source>Clear</source>
<translation>Очистить</translation>
</message>
<message>
<location filename="../graphic.ui" line="257"/>
<source>Close</source>
<translation>Закрыть</translation>
</message>
<message>
<location filename="../graphic.ui" line="408"/>
<source>Cursor: ( ; )</source>
<translation>Курсор: ( ; )</translation>
</message>
<message>
<location filename="../graphic.cpp" line="196"/>
<location filename="../graphic.cpp" line="763"/>
<source>Cursor: </source>
<translation>Курсор: </translation>
</message>
<message>
<location filename="../graphic.cpp" line="206"/>
<source>Selection</source>
<translation>Выбрано</translation>
</message>
<message>
<location filename="../graphic.cpp" line="207"/>
<source>Size</source>
<translation>Размер</translation>
</message>
<message>
<location filename="../graphic.cpp" line="211"/>
<location filename="../graphic.cpp" line="217"/>
<source>Range</source>
<translation>Диапазон</translation>
</message>
<message>
<location filename="../graphic.cpp" line="212"/>
<location filename="../graphic.cpp" line="218"/>
<source>Length</source>
<translation>Длина</translation>
</message>
<message>
<location filename="../graphic.cpp" line="316"/>
<location filename="../graphic.cpp" line="346"/>
<source>Cursor</source>
<translation>Курсор</translation>
</message>
<message>
<location filename="../graphic.cpp" line="487"/>
<source>Save Image</source>
<translation>Соханение изображения</translation>
</message>
<message>
<location filename="../graphic.cpp" line="532"/>
<source>y(x)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphic.cpp" line="1075"/>
<source>Check all</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GraphicConf</name>
<message>
<location filename="../graphic_conf.ui" line="17"/>
<source>Graphic parameters</source>
<translation>Параметры графика</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="32"/>
<source>Appearance</source>
<translation>Внешний вид</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="46"/>
<source>Border inputs</source>
<translation>Граничные поля ввода</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="53"/>
<source>Antialiasing</source>
<translation>Антиалиасинг</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="60"/>
<source>Status bar</source>
<translation>Строка состояния</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="67"/>
<source>OpenGL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="74"/>
<source>Legend</source>
<translation>Легенда</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="94"/>
<source>Background color:</source>
<translation>Цвет фона:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="114"/>
<source>Text color:</source>
<translation>Цвет текста:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="245"/>
<source>Grid</source>
<translation>Сетка</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="380"/>
<source>Margins</source>
<translation>Отступы</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="392"/>
<location filename="../graphic_conf.ui" line="402"/>
<location filename="../graphic_conf.ui" line="422"/>
<location filename="../graphic_conf.ui" line="462"/>
<location filename="../graphic_conf.ui" line="482"/>
<source> px</source>
<translation> пикс</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="412"/>
<source>All:</source>
<translation>Все:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="432"/>
<source>Right:</source>
<translation>Правый:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="442"/>
<source>Left:</source>
<translation>Левый:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="452"/>
<source>Bottom:</source>
<translation>Нижний:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="472"/>
<source>Top:</source>
<translation>Верхний:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="161"/>
<location filename="../graphic_conf.ui" line="263"/>
<source>Color:</source>
<translation>Цвет:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="175"/>
<location filename="../graphic_conf.ui" line="277"/>
<source>Style:</source>
<translation>Стиль:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="287"/>
<source>Width:</source>
<translation>Толщина:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="317"/>
<source>Step X:</source>
<translation>Шаг X:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="324"/>
<source>Step Y:</source>
<translation>Шаг Y:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="347"/>
<source>Auto step</source>
<translation>Автоматическая</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="133"/>
<source>Graphics</source>
<translation>Графики</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="185"/>
<source>Lines width:</source>
<translation>Толщина линий:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="205"/>
<source>Points width:</source>
<translation>Толщина точек:</translation>
</message>
<message>
<location filename="../graphic_conf.ui" line="225"/>
<source>Fill:</source>
<translation>Заливка:</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>NoPen</source>
<translation>Без линий</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>Solid</source>
<translation>Сплошная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="7"/>
<source>Dash</source>
<translation>Штриховая</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dot</source>
<translation>Пунктирная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dash-Dot</source>
<translation>Штрих-пунктирная</translation>
</message>
<message>
<location filename="../graphic_conf.cpp" line="8"/>
<source>Dash-Dot-Dot</source>
<translation>Штрих-пунктир-пунктирная</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 type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Value</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="341"/>
<source>Comment</source>
<translation type="unfinished"></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 type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="361"/>
<source>Expand all</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigwidget.cpp" line="362"/>
<source>Collapse all</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QPointEdit</name>
<message>
<location filename="../qpointedit.cpp" line="11"/>
<location filename="../qpointedit.cpp" line="28"/>
<source>X</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpointedit.cpp" line="12"/>
<location filename="../qpointedit.cpp" line="29"/>
<source>Y</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QRectEdit</name>
<message>
<location filename="../qrectedit.cpp" line="17"/>
<location filename="../qrectedit.cpp" line="48"/>
<source>X</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="18"/>
<location filename="../qrectedit.cpp" line="49"/>
<source>Y</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="19"/>
<location filename="../qrectedit.cpp" line="50"/>
<source>Height</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qrectedit.cpp" line="20"/>
<location filename="../qrectedit.cpp" line="51"/>
<source>Width</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Shortcuts</name>
<message>
<location filename="../shortcuts.cpp" line="33"/>
<location filename="../shortcuts.cpp" line="49"/>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../shortcuts.cpp" line="33"/>
<location filename="../shortcuts.cpp" line="49"/>
<source>Shortcut</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StringListEdit</name>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="20"/>
<location filename="../qpiconfigvaluewidget.cpp" line="37"/>
<source>Add</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="21"/>
<location filename="../qpiconfigvaluewidget.cpp" line="38"/>
<source>Remove</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qpiconfigvaluewidget.cpp" line="22"/>
<location filename="../qpiconfigvaluewidget.cpp" line="39"/>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -0,0 +1 @@
qad_plugin(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,31 @@
#ifndef CHARDIALOGPLUGIN_H
#define CHARDIALOGPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef CLINEEDITPLUGIN_H
#define CLINEEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef COLORBUTTONPLUGIN_H
#define COLORBUTTONPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef ECOMBOBOXPLUGIN_H
#define ECOMBOBOXPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef ICONEDLABEPLUGIN_H
#define ICONEDLABEPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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 "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,40 @@
#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 "qad_widgets.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));
}
QList<QDesignerCustomWidgetInterface * > QADWidgets::customWidgets() const {
return m_widgets;
}
Q_EXPORT_PLUGIN2(qad_widgets_plugin, QADWidgets)

View File

@@ -0,0 +1,21 @@
#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)
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,31 @@
#ifndef QCODEEDITPLUGIN_H
#define QCODEEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QIPEDITPLUGIN_H
#define QIPEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QPICONFIGPLUGIN_H
#define QPICONFIGPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QPICONSOLEPLUGIN_H
#define QPICONSOLEPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QPOINTEDITPLUGIN_H
#define QPOINTEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QRECTEDITPLUGIN_H
#define QRECTEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef QVARIANTEDITPLUGIN_H
#define QVARIANTEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef SHORTCUTSPLUGIN_H
#define SHORTCUTSPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,31 @@
#ifndef SPINSLIDERPLUGIN_H
#define SPINSLIDERPLUGIN_H
#include <QDesignerCustomWidgetInterface>
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,40 @@
<RCC>
<qresource prefix="/">
<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>
</qresource>
</RCC>

1003
qad/widgets/qcodeedit.cpp Normal file
View File

@@ -0,0 +1,1003 @@
#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>
QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) {
prev_lc = auto_comp_pl = -1;
textCode = textLines = 0;
timer = 0;
_ignore_focus_out = _destructor = 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));
widget_help = new QFrame();
widget_help->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
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);
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);
//completer->setColumnWidth(0, 180);
completer->resize(500, 200);
textCode = new QPlainTextEdit();
textLines = new QPlainTextEdit();
textCode->setFrameShadow(QFrame::Plain);
textCode->setFrameShape(QFrame::NoFrame);
textCode->setLineWrapMode(QPlainTextEdit::NoWrap);
textCode->setTabChangesFocus(false);
textLines->setFrameShadow(QFrame::Plain);
textLines->setFrameShape(QFrame::NoFrame);
textLines->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
textLines->setFocusPolicy(Qt::NoFocus);
textLines->setTextInteractionFlags(Qt::NoTextInteraction);
textLines->setLineWrapMode(QPlainTextEdit::NoWrap);
textLines->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
textLines->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
textLines->viewport()->setAutoFillBackground(false);
textLines->viewport()->setCursor(Qt::ArrowCursor);
textLines->setFixedWidth(textLines->fontMetrics().width(" "));
setLayout(new QBoxLayout(QBoxLayout::BottomToTop));
layout()->setContentsMargins(0, 0, 0, 0);
QFrame * frame = new QFrame();
frame->setFrameShadow(QFrame::Sunken);
frame->setFrameShape(QFrame::StyledPanel);
frame->setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
frame->layout()->setContentsMargins(0, 0, 0, 0);
frame->layout()->setSpacing(0);
frame->layout()->addWidget(textLines);
frame->layout()->addWidget(textCode);
layout()->addWidget(frame);
QAction * a = new QAction(this);
a->setShortcut(QKeySequence("Shift+Tab"));
a->setShortcutContext(Qt::WidgetShortcut);
connect(a, SIGNAL(triggered(bool)), this, SLOT(deindent()));
textCode->addAction(a);
a = new QAction(this);
a->setShortcut(QKeySequence("Ctrl+D"));
a->setShortcutContext(Qt::WidgetShortcut);
connect(a, SIGNAL(triggered(bool)), this, SLOT(deleteLine()));
textCode->addAction(a);
frame->setFocusProxy(textCode);
QTextOption to = textLines->document()->defaultTextOption();
to.setAlignment(Qt::AlignTop | Qt::AlignRight);
textLines->document()->setDefaultTextOption(to);
setShowSpaces(true);
connect(completer, SIGNAL(itemDoubleClicked(QTreeWidgetItem * ,int)), this, SLOT(commitCompletition()));
connect(textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), textLines->verticalScrollBar(), SLOT(setValue(int)));
connect(textCode, SIGNAL(textChanged()), this, SLOT(updateLines()));
connect(textCode, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
connect(textCode, SIGNAL(cursorPositionChanged()), this, SLOT(textEdit_cursorPositionChanged()));
connect(textCode, SIGNAL(selectionChanged()), this, SLOT(textEdit_selectionChanged()));
updateLines();
registerAutoCompletitionClass(-1, QCodeEdit::Keyword, "Words", QIcon(":/icons/code-word.png"));
}
QCodeEdit::~QCodeEdit() {
_destructor = true;
delete textCode;
delete textLines;
delete completer;
//for (int i = 0; i < 2; ++i)
// delete lbl_help[i];
delete widget_help;
}
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);
textCode->removeEventFilter(this);
textCode->viewport()->removeEventFilter(this);
textLines->viewport()->removeEventFilter(this);
return QWidget::eventFilter(o, e);
}
if (textLines) {
if (o == 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());
#endif
QApplication::sendEvent(textCode->viewport(), e);
return true;
}
if (e->type() == QEvent::Wheel) {
QApplication::sendEvent(textCode->viewport(), e);
return true;
}
}
}
if (o == completer) {
//qDebug() << o << e;
if (e->type() == QEvent::WindowActivate)
_ignore_focus_out = true;
//qDebug() << e;
return QWidget::eventFilter(o, e);
}
if (textCode) {
if (o == textCode->viewport()) {
if (e->type() == QEvent::MouseButtonPress) {
completer->hide();
hideHelp();
}
if (e->type() == QEvent::ToolTip) {
QTextCursor tc = textCode->cursorForPosition(((QHelpEvent*)e)->pos());
tc.select(QTextCursor::WordUnderCursor);
raiseHelp(tc);
}
return QWidget::eventFilter(o, e);
}
if (o == textCode) {
//qDebug() << o << e;
QMetaObject::invokeMethod(this, "syncScrolls", Qt::QueuedConnection);
QKeyEvent * ke;
QChar kc(0);
switch (e->type()) {
case QEvent::KeyPress:
ke = (QKeyEvent * )e;
switch (ke->key()) {
case Qt::Key_Space:
if (ke->modifiers().testFlag(Qt::ControlModifier)) {
invokeAutoCompletition(true);
return true;
}
break;
case Qt::Key_Escape:
completer->hide();
hideHelp();
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 (textCode->textCursor().selectedText().isEmpty())
QMetaObject::invokeMethod(this, "autoIndent", Qt::QueuedConnection);
break;
case Qt::Key_Tab:
if (!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);
textCode->installEventFilter(this);
textCode->viewport()->installEventFilter(this);
textLines->viewport()->installEventFilter(this);
}
void QCodeEdit::timerEvent(QTimerEvent * ) {
parse();
emit parseRequest();
killTimer(timer);
timer = 0;
}
void QCodeEdit::applyExtraSelection() {
textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << 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::syncScrolls() {
textLines->verticalScrollBar()->setValue(textCode->verticalScrollBar()->value());
}
void QCodeEdit::deleteLine() {
QTextCursor tc = 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);
textCode->setTextCursor(tc);
}
void QCodeEdit::copyLineUp() {
QTextCursor tc = 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();
textCode->setTextCursor(tc);
}
void QCodeEdit::copyLineDown() {
QTextCursor tc = 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();
textCode->setTextCursor(tc);
}
void QCodeEdit::moveLineUp() {
QTextCursor tc = 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();
textCode->setTextCursor(tc);
}
void QCodeEdit::moveLineDown() {
QTextCursor tc = 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();
textCode->setTextCursor(tc);
}
void QCodeEdit::indent() {
QTextCursor tc = 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);
textCode->setTextCursor(tc);
}
void QCodeEdit::deindent() {
QTextCursor tc = 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);
textCode->setTextCursor(tc);
}
void QCodeEdit::autoIndent() {
QTextCursor tc = 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);
textCode->setTextCursor(stc);
}
void QCodeEdit::scrollToTop() {
prev_lc = -1;
updateLines();
textCode->verticalScrollBar()->setValue(0);
textLines->verticalScrollBar()->setValue(0);
}
void QCodeEdit::updateLines() {
if (timer > 0) killTimer(timer);
timer = startTimer(500);
textCode->setTabStopWidth(textCode->fontMetrics().width(" "));
int lc = textCode->document()->lineCount();
if (prev_lc == lc) return;
prev_lc = lc;
textLines->setFixedWidth(textLines->fontMetrics().width(QString(" %1").arg(lc)));
textLines->clear();
for (int i = 1; i <= lc; ++i)
textLines->appendPlainText(QString("%1").arg(i));
textLines->verticalScrollBar()->setValue(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);
//qDebug() << "help" << scope;
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;
}
es_cursor.cursor = tc;
applyExtraSelection();
tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, st.size());
lbl_help[0]->setFont(font());
widget_help->resize(widget_help->sizeHint());
widget_help->move(textCode->mapToGlobal(textCode->cursorRect(tc).topLeft() - QPoint(0, widget_help->height() + 8)));
widget_help->show();
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 = 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(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(textCode->document()->begin()), stc;
QStringList acwl;
tc = QTextCursor(textCode->document()->begin());
while (true) {
tc = 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 = 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(textCode->textCursor(), &arg);
if (!htc.isNull()) {
//qDebug() << "raise";
raiseHelp(htc, arg);
}
bool ok;
QPair<QStringList, QString> scope = getScope(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(textCode->mapToGlobal(textCode->cursorRect().bottomRight()));
completer->setVisible(completer->topLevelItemCount() > 0);
}
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 = textCode->textCursor(), stc = tc;
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
bool ins_br = true, shifted = false;
if (!tc.selectedText().isEmpty()) {
if (!tc.selectedText()[0].isLetterOrNumber() && !tc.selectedText()[0].isSpace()) {
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 = stc;
if (shifted)
tc.movePosition(QTextCursor::Right);
}
textCode->setTextCursor(tc);
textCode->textCursor().insertText(ins);
tc = textCode->textCursor();
if (ins_br) {
if (ret == "void") {
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
if (tc.selectedText() != ";") {
textCode->textCursor().insertText(";");
tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2);
}
}
if (ins.endsWith(")") && !completer->currentItem()->text(1).endsWith("()")) {
tc.movePosition(QTextCursor::Left);
textCode->setTextCursor(tc);
}
} else {
if (completer->currentItem()->text(1).endsWith(")")) {
tc.movePosition(QTextCursor::Right);
textCode->setTextCursor(tc);
}
if (completer->currentItem()->text(1).endsWith("()")) {
tc.movePosition(QTextCursor::Right);
textCode->setTextCursor(tc);
}
}
completer->hide();
}
void QCodeEdit::textEdit_cursorPositionChanged() {
es_line.cursor = textCode->textCursor();
es_line.cursor.select(QTextCursor::LineUnderCursor);
es_line.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
applyExtraSelection();
}
void QCodeEdit::textEdit_textChanged() {
updateLines();
}
void QCodeEdit::textEdit_selectionChanged() {
es_selected.clear();
QString sf = textCode->textCursor().selectedText();
if (sf.trimmed().isEmpty() || sf.contains("\n")) {
applyExtraSelection();
return;
}
QTextCursor tc(textCode->document()->begin());
QTextEdit::ExtraSelection es;
es.format.setBackground(QColor(251, 250, 150));
while (true) {
tc = 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 = textCode->document()->defaultTextOption();
to.setFlags(yes ? QTextOption::ShowTabsAndSpaces : (QTextOption::Flags)0);
textCode->document()->setDefaultTextOption(to);
}

130
qad/widgets/qcodeedit.h Normal file
View File

@@ -0,0 +1,130 @@
#ifndef QCODEEDIT_H
#define QCODEEDIT_H
#include <QDebug>
#include <QPlainTextEdit>
#include <QTreeWidget>
#include <QScrollBar>
#include "iconedlabel.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
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)
public:
QCodeEdit(QWidget * parent = 0);
~QCodeEdit();
enum ACClassType {
Keyword,
Function,
Namespace
};
QTextCursor textCursor() const {return textCode->textCursor();}
QTextDocument * document() const {return textCode->document();}
void setTextCursor(const QTextCursor & c) {textCode->setTextCursor(c);}
void centerCursor() {textCode->centerCursor(); updateLines();}
void insertText(const QString & text) {textCode->insertPlainText(text); updateLines();}
void appendText(const QString & text) {textCode->appendPlainText(text); updateLines();}
void setCustomExtraSelection(const QList<QTextEdit::ExtraSelection> & es) {es_custom = es; applyExtraSelection();}
QRect cursorRect() const {return textCode->cursorRect();}
QRect cursorRect(const QTextCursor & cursor) const {return textCode->cursorRect(cursor);}
QString text() const {return textCode->toPlainText();}
QStringList cursorScope() const {return cursor_scope;}
bool showSpaces() const {return spaces_;}
bool showLineNumbers() const {return textLines->isVisible();}
QPlainTextEdit * textEdit() const {return textCode;}
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() {}
QString selectArg(QString s, int arg);
void raiseHelp(QTextCursor tc, int arg = -1);
void hideHelp();
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);
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;
};
QPlainTextEdit * textCode, * textLines;
QTreeWidget * completer;
IconedLabel * lbl_help[2];
QFrame * widget_help;
QTextEdit::ExtraSelection es_line, es_cursor;
QList<QTextEdit::ExtraSelection> es_selected, es_custom;
QMap<int, ACClass> ac_classes;
QStringList cursor_scope;
int prev_lc, auto_comp_pl, timer;
bool spaces_, _ignore_focus_out, _first, _destructor;
bool eventFilter(QObject * o, QEvent * e);
void showEvent(QShowEvent * );
void timerEvent(QTimerEvent * );
void applyExtraSelection();
void nextCompletition();
void previousCompletition();
private slots:
void syncScrolls();
void deleteLine();
void copyLineUp();
void copyLineDown();
void moveLineUp();
void moveLineDown();
void indent();
void deindent();
void autoIndent();
void invokeAutoCompletition(bool force = false);
void commitCompletition();
void textEdit_cursorPositionChanged();
void textEdit_textChanged();
void textEdit_selectionChanged();
public slots:
void updateLines();
void scrollToTop();
void setFocus() {textCode->setFocus();}
void setText(const QString & t) {textCode->setPlainText(t);}
void setShowSpaces(bool yes);
void setShowLineNumbers(bool yes) {textLines->setVisible(yes);}
signals:
void textChanged();
void parseRequest();
};
//Q_DECLARE_OPERATORS_FOR_FLAGS(QPIConsole::Formats)
QT_END_NAMESPACE
QT_END_HEADER
#endif // QCODEEDIT_H

82
qad/widgets/qipedit.cpp Normal file
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);
}
}

48
qad/widgets/qipedit.h Normal file
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

268
qad/widgets/qpiconsole.cpp Normal file
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);
}

187
qad/widgets/qpiconsole.h Normal file
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);
}

42
qad/widgets/qpointedit.h Normal file
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

56
qad/widgets/qrectedit.cpp Normal file
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);
}

51
qad/widgets/qrectedit.h Normal file
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,449 @@
#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->setMaximumWidth(combo->height());
butt_del->setMaximumWidth(combo->height());
butt_clear->setMaximumWidth(combo->height());
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);
butt_select = new QPushButton(this);
//butt_select->setIconSize(QSize(16, 16));
butt_select->setMaximumWidth(line->height());
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::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) {
_empty = 0;
_line = 0;
_check = 0;
_color = 0;
_list = 0;
_date = 0;
_spin = 0;
_rect = 0;
_point = 0;
_path = 0;
_enum = 0;
_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:
_spin = new QDoubleSpinBox(this);
_spin->setDecimals(5);
_spin->setRange(-1E+199, 1E+199);
_cur_edit = _spin;
connect(_spin, 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()));
}
}
//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 double(_spin->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);
}
}
}
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 (_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 (_cur_edit) _cur_edit->blockSignals(false);
}
void QVariantEdit::_delete() {
if (_cur_edit)
delete _cur_edit;
_cur_edit = 0;
_empty = 0;
_line = 0;
_check = 0;
_color = 0;
_list = 0;
_date = 0;
_spin = 0;
_rect = 0;
_point = 0;
_path = 0;
_enum = 0;
}
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::_changed() {
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
emit valueChanged(value());
}

129
qad/widgets/qvariantedit.h Normal file
View File

@@ -0,0 +1,129 @@
#ifndef QVARIANTEDIT_H
#define QVARIANTEDIT_H
#include "clineedit.h"
#include "ecombobox.h"
#include "colorbutton.h"
#include "qrectedit.h"
#include "qpointedit.h"
#include "qad_types.h"
#include <QCheckBox>
#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);
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:
void resizeEvent(QResizeEvent * );
void _recreate(const QVariant & new_value);
void _delete();
void _resize() {if (_cur_edit) _cur_edit->resize(size());}
void _newPath();
void _setEnum(const QAD::Enum & v);
void _setFile(const QAD::File & v);
void _setDir(const QAD::Dir & v);
QLabel * _empty;
CLineEdit * _line;
QCheckBox * _check;
ColorButton * _color;
StringListEdit * _list;
QDateTimeEdit * _date;
QDoubleSpinBox * _spin;
QRectEdit * _rect;
QPointEdit * _point;
PathEdit * _path;
EComboBox * _enum;
QWidget * _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,123 @@
/*
Peri4 Paint
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "session_manager.h"
void SessionManager::save() {
if (file_.isEmpty()) return;
QPIConfig sr(file_);
for (int i = 0; i < mwindows.size(); ++i) {
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) {
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 < tabs.size(); ++i)
sr.setValue(tabs[i].first, tabs[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);
sr.writeAll();
emit saving(sr);
}
void SessionManager::load(bool onlyMainwindow) {
if (file_.isEmpty()) return;
QPIConfig sr(file_);
for (int i = 0; i < mwindows.size(); ++i) {
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) {
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 < 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 < 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);
emit loading(sr);
}

View File

@@ -0,0 +1,99 @@
/*
Peri4 Paint
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SESSION_MANAGER_H
#define SESSION_MANAGER_H
#include <QPair>
#include <QMainWindow>
#include <QCheckBox>
#include <QLineEdit>
#include <QDoubleSpinBox>
#include <QAction>
#include <QComboBox>
#include <QTabWidget>
#include <QSplitter>
#include "spinslider.h"
#include "qpiconfig.h"
class SessionManager: public QObject
{
Q_OBJECT
public:
SessionManager(const QString & file = QString()) {setFile(file);}
~SessionManager() {;}
inline void setFile(const QString & file) {file_ = file;}
inline void addEntry(QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(e->objectName(), e));}
inline void addEntry(QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(e->objectName(), e));}
inline void addEntry(QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(e->objectName(), e));}
inline void addEntry(QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(e->objectName(), e));}
inline void addEntry(QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(e->objectName(), e));}
inline void addEntry(QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(e->objectName(), e));}
inline void addEntry(SpinSlider * e) {spinsliders.push_back(QPair<QString, SpinSlider * >(e->objectName(), e));}
inline void addEntry(QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(e->objectName(), e));}
inline void addEntry(QAction * e) {actions.push_back(QPair<QString, QAction * >(e->objectName(), e));}
inline void addMainWidget(QWidget * e) {widgets.push_back(QPair<QString, QWidget * >(e->objectName(), e));}
inline void addEntry(const QString & name, QMainWindow * e) {mwindows.push_back(QPair<QString, QMainWindow * >(name, e));}
inline void addEntry(const QString & name, QCheckBox * e) {checks.push_back(QPair<QString, QCheckBox * >(name, e));}
inline void addEntry(const QString & name, QLineEdit * e) {lines.push_back(QPair<QString, QLineEdit * >(name, e));}
inline void addEntry(const QString & name, QComboBox * e) {combos.push_back(QPair<QString, QComboBox * >(name, e));}
inline void addEntry(const QString & name, QDoubleSpinBox * e) {dspins.push_back(QPair<QString, QDoubleSpinBox * >(name, e));}
inline void addEntry(const QString & name, QSpinBox * e) {spins.push_back(QPair<QString, QSpinBox * >(name, e));}
inline void addEntry(const QString & name, SpinSlider * e) {spinsliders.push_back(QPair<QString, SpinSlider * >(name, e));}
inline void addEntry(const QString & name, QTabWidget * e) {tabs.push_back(QPair<QString, QTabWidget * >(name, e));}
inline void addEntry(const QString & name, QAction * e) {actions.push_back(QPair<QString, QAction * >(name, e));}
inline void addEntry(const QString & name, QStringList * e) {stringlists.push_back(QPair<QString, QStringList * >(name, e));}
inline void addEntry(const QString & name, QString * e) {strings.push_back(QPair<QString, QString * >(name, e));}
inline void addEntry(const QString & name, QColor * e) {colors.push_back(QPair<QString, QColor * >(name, e));}
inline void addEntry(const QString & name, bool * e) {bools.push_back(QPair<QString, bool * >(name, e));}
inline void addEntry(const QString & name, int * e) {ints.push_back(QPair<QString, int * >(name, e));}
inline void addEntry(const QString & name, float * e) {floats.push_back(QPair<QString, float * >(name, e));}
inline void addMainWidget(const QString & name, QWidget * e) {widgets.push_back(QPair<QString, QWidget * >(name, e));}
void save();
void load(bool onlyMainwindow = false);
private:
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, QTabWidget * > > tabs;
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_;
signals:
void loading(QPIConfig & );
void saving(QPIConfig & );
};
#endif // SESSION_MANAGER_H

233
qad/widgets/shortcuts.cpp Normal file
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;
}

90
qad/widgets/shortcuts.h Normal file
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;
}

102
qad/widgets/spinslider.h Normal file
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