diff --git a/CMakeLists.txt b/CMakeLists.txt index 22dd7b1..1ab3cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(QAD) set(QAD_MAJOR 2) -set(QAD_MINOR 19) +set(QAD_MINOR 20) set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) diff --git a/icons/layer-visible-off.png b/icons/layer-visible-off.png index 03ca47d..35a2be4 100644 Binary files a/icons/layer-visible-off.png and b/icons/layer-visible-off.png differ diff --git a/libs/application/edockwidget.cpp b/libs/application/edockwidget.cpp index 9fe05da..ea94345 100644 --- a/libs/application/edockwidget.cpp +++ b/libs/application/edockwidget.cpp @@ -6,6 +6,27 @@ #include +EDockWidget::EDockWidget(const QString & title, QWidget * parent, Qt::WindowFlags flags): QDockWidget(title, parent, flags) { + init(); +} + + +EDockWidget::EDockWidget(QWidget * parent, Qt::WindowFlags flags): QDockWidget(parent, flags) { + init(); +} + + +EDockWidget::~EDockWidget() { + delete btn_hide; + delete btn_dock; + delete btn_maximize; + delete lbl_title; + delete lbl_icon; + delete header; + delete empty_header; +} + + void EDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) { btn_dock->setVisible(features.testFlag(DockWidgetFloatable)); btn_hide->setVisible(features.testFlag(DockWidgetClosable)); @@ -31,6 +52,16 @@ void EDockWidget::setWindowIcon(const QIcon & icon) { } +void EDockWidget::setEmptyHeader() { + if (titleBarWidget() != empty_header) setTitleBarWidget(empty_header); +} + + +void EDockWidget::setStandardHeader() { + if (titleBarWidget() != header) setTitleBarWidget(header); +} + + bool EDockWidget::event(QEvent * e) { if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) { updateStyle(); @@ -39,9 +70,19 @@ bool EDockWidget::event(QEvent * e) { } +void EDockWidget::changeEvent(QEvent * e) { + if (e->type() == QEvent::WindowStateChange || e->type() == QEvent::LanguageChange) { + updateStyle(); + } + QDockWidget::changeEvent(e); +} + + void EDockWidget::init() { header = new QFrame(); header->setFrameShape(QFrame::StyledPanel); + empty_header = new QWidget(); + empty_header->setLayout(new QBoxLayout(QBoxLayout::BottomToTop)); QBoxLayout * lay = new QBoxLayout(features().testFlag(QDockWidget::DockWidgetVerticalTitleBar) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); lay->setContentsMargins(2, 2, 2, 2); @@ -62,38 +103,62 @@ void EDockWidget::init() { // #endif lbl_title = new QLabel(windowTitle()); lbl_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - btn_dock = new QToolButton(); - // btn_dock->setIconSize(QSize(16, 16)); - btn_dock->setAutoRaise(true); - btn_dock->setFocusPolicy(Qt::NoFocus); - btn_dock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - btn_hide = new QToolButton(); - // btn_hide->setIconSize(QSize(16, 16)); - btn_hide->setAutoRaise(true); - btn_hide->setFocusPolicy(Qt::NoFocus); - btn_hide->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(btn_dock, SIGNAL(clicked(bool)), this, SLOT(dockClicked())); - connect(btn_hide, SIGNAL(clicked(bool)), this, SLOT(hide())); + auto createButton = [this](const char * slot) { + auto * ret = new QToolButton(); + ret->setAutoRaise(true); + ret->setFocusPolicy(Qt::NoFocus); + ret->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + // ret->setIconSize(QSize(16, 16)); + connect(ret, SIGNAL(clicked(bool)), this, slot); + return ret; + }; + btn_dock = createButton(SLOT(dockClicked())); + btn_maximize = createButton(SLOT(maximize())); + btn_hide = createButton(SLOT(hide())); lay->addWidget(lbl_icon); lay->addWidget(lbl_title); lay->addWidget(btn_dock); + lay->addWidget(btn_maximize); lay->addWidget(btn_hide); header->setLayout(lay); updateStyle(); setTitleBarWidget(header); + connect(this, &QDockWidget::topLevelChanged, this, &EDockWidget::updateStyle); } void EDockWidget::updateStyle() { + int eh_m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin); + empty_header->layout()->setContentsMargins(eh_m, eh_m, 0, 0); QSize icon_size = preferredIconSize(0.75, this); int bm = 2 * style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this); QSize btn_size = icon_size; btn_size += QSize(bm, bm); - btn_dock->setIcon(style()->standardIcon(QStyle::SP_TitleBarNormalButton)); - btn_dock->setIconSize(icon_size); - btn_dock->setFixedSize(btn_size); - btn_hide->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); - btn_hide->setIconSize(icon_size); - btn_hide->setFixedSize(btn_size); lbl_icon->setFixedSize(preferredIconSize(1.5, this)); + auto restyleButton = [this, icon_size, btn_size](QToolButton * btn, QStyle::StandardPixmap pm) { + btn->setIcon(style()->standardIcon(pm)); + btn->setIconSize(icon_size); + btn->setFixedSize(btn_size); + }; + restyleButton(btn_dock, isFloating() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton); + restyleButton(btn_maximize, isMaximized() ? QStyle::SP_TitleBarNormalButton : QStyle::SP_TitleBarMaxButton); + restyleButton(btn_hide, QStyle::SP_TitleBarCloseButton); + btn_dock->setToolTip(isFloating() ? tr("Dock") : tr("Undock")); + btn_maximize->setToolTip(isMaximized() ? tr("Show normal") : tr("Maximize")); + btn_hide->setToolTip(tr("Hide")); +} + + +void EDockWidget::dockClicked() { + if (!isFloating() && isMaximized()) showNormal(); + setFloating(!isFloating()); +} + + +void EDockWidget::maximize() { + if (!isFloating()) setFloating(true); + if (isMaximized()) + showNormal(); + else + showMaximized(); } diff --git a/libs/application/edockwidget.h b/libs/application/edockwidget.h index b0645eb..6d4ae87 100644 --- a/libs/application/edockwidget.h +++ b/libs/application/edockwidget.h @@ -35,34 +35,31 @@ class QAD_APPLICATION_EXPORT EDockWidget: public QDockWidget { Q_OBJECT public: - explicit EDockWidget(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()) - : QDockWidget(title, parent, flags) { - init(); - } - explicit EDockWidget(QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()): QDockWidget(parent, flags) { init(); } - ~EDockWidget() { - delete btn_hide; - delete btn_dock; - delete lbl_title; - delete lbl_icon; - delete header; - } + explicit EDockWidget(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit EDockWidget(QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()); + ~EDockWidget(); void setFeatures(QDockWidget::DockWidgetFeatures features); void setWindowTitle(const QString & title); void setWindowIcon(const QIcon & icon); + void setEmptyHeader(); + void setStandardHeader(); + private: - bool event(QEvent * e); + bool event(QEvent * e) override; + void changeEvent(QEvent * e) override; void init(); void updateStyle(); QFrame * header; + QWidget * empty_header; QLabel *lbl_title, *lbl_icon; - QToolButton *btn_hide, *btn_dock; + QToolButton *btn_hide, *btn_dock, *btn_maximize; private slots: - void dockClicked() { setFloating(!isFloating()); } + void dockClicked(); + void maximize(); }; #endif // EDOCKWIDGET_H diff --git a/libs/application/emainwindow.cpp b/libs/application/emainwindow.cpp index 40dddb9..720e107 100644 --- a/libs/application/emainwindow.cpp +++ b/libs/application/emainwindow.cpp @@ -4,6 +4,7 @@ #include #include #include +#include EMainWindow::EMainWindow(QWidget * parent) @@ -11,8 +12,7 @@ EMainWindow::EMainWindow(QWidget * parent) , action_show_all_tools(this) , action_hide_all_tools(this) , action_show_all_docks(this) - , action_hide_all_docks(this) - , first_show(true) { + , action_hide_all_docks(this) { menu_recent = 0; action_clear_recent = new QAction(QIcon(":/icons/edit-clear.png"), tr("Clear recent list"), this); connect(action_clear_recent, SIGNAL(triggered()), this, SLOT(clearRecent())); @@ -268,8 +268,8 @@ void EMainWindow::initDocks() { void EMainWindow::initSession() { - connect(&session, SIGNAL(loading(QPIConfig &)), this, SLOT(sessionLoading(QPIConfig &))); - connect(&session, SIGNAL(saving(QPIConfig &)), this, SLOT(sessionSaving(QPIConfig &))); + connect(&session, &SessionManager::loading, this, [this](QPIConfig & conf) { loadingSession(conf); }); + connect(&session, &SessionManager::saving, this, [this](QPIConfig & conf) { savingSession(conf); }); } @@ -289,6 +289,12 @@ bool EMainWindow::checkSave() { } +void EMainWindow::setChanged(bool yes) { + is_changed = yes; + setWindowModified(yes); +} + + void EMainWindow::changedDock() { if (isHidden()) return; QSet invalid_tab_docks; @@ -325,30 +331,19 @@ void EMainWindow::changedDock() { for (QDockWidget * d: docks) { if (!d->titleBarWidget()) continue; - QWidget * ctb = d->titleBarWidget(); - if (!d->property("__titleWidget").isValid()) { - d->setProperty("__titleWidget", qulonglong(ctb)); - QWidget * ntb = new QWidget(); - int m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin); - ntb->setLayout(new QBoxLayout(QBoxLayout::BottomToTop)); - ntb->layout()->setContentsMargins(m, m, 0, 0); - d->setProperty("__titleEmptyWidget", qulonglong(ntb)); - } if (!tdocks.contains(d)) { // qDebug() << "add dock" << d; tdocks << d; connect(d, &QObject::destroyed, this, [this, d]() { tdocks.removeOne(d); }); d->installEventFilter(this); } - // qDebug() << d->windowTitle() << tabifiedDockWidgets(d); - if (tabifiedDockWidgets(d).isEmpty() || invalid_tab_docks.contains(d)) { - if (d->titleBarWidget() != (QWidget *)(d->property("__titleWidget").toULongLong())) - d->setTitleBarWidget((QWidget *)(d->property("__titleWidget").toULongLong())); - } else { - if (d->titleBarWidget() != (QWidget *)(d->property("__titleEmptyWidget").toULongLong())) { - d->setTitleBarWidget((QWidget *)(d->property("__titleEmptyWidget").toULongLong())); - d->layout()->setContentsMargins(0, 20, 0, 0); - } + auto * ed = qobject_cast(d); + if (ed) { + // qDebug() << d->windowTitle() << tabifiedDockWidgets(d); + if (tabifiedDockWidgets(d).isEmpty() || invalid_tab_docks.contains(d)) + ed->setStandardHeader(); + else + ed->setEmptyHeader(); } } } diff --git a/libs/application/emainwindow.h b/libs/application/emainwindow.h index 63c7e75..5656878 100644 --- a/libs/application/emainwindow.h +++ b/libs/application/emainwindow.h @@ -88,59 +88,47 @@ public: void setRecentMenu(QMenu * m); int maxRecentItems() const { return max_recent; } + bool isChanged() const { return is_changed; } protected: - // Qt`s overloaded - void showEvent(QShowEvent *); - void closeEvent(QCloseEvent *); - bool eventFilter(QObject * o, QEvent * e); - void changeEvent(QEvent * e); - QMenu * createPopupMenu(); - void addToRecent(const QString & path); - void prepareRecent(); + void showEvent(QShowEvent *) override; + void closeEvent(QCloseEvent *) override; + bool eventFilter(QObject * o, QEvent * e) override; + void changeEvent(QEvent * e) override; + QMenu * createPopupMenu() override; - void init(const QString & config) { - session.setFile(config); - initMenus(); - initSession(); - loadSession(); - } // unusable void saveSession(); void loadSession(); - virtual void savingSession(QPIConfig & conf) {} + void setChanged(bool yes = true); + void addToRecent(const QString & path); + virtual void loadingSession(QPIConfig & conf) {} + virtual void savingSession(QPIConfig & conf) {} virtual QSize dockTabsIconSize() const { return iconSize(); } virtual QString loadFilter() { return "All files(*)"; } virtual QString saveFilter() { return "All files(*)"; } + SessionManager session; + QString file_name; + +private: + void prepareRecent(); + bool checkSave(); - void setChanged(bool yes = true) { - isChanged = yes; - setWindowModified(yes); - } void initMenus(); void initDocks(); void initSession(); QAction action_show_all_tools, action_hide_all_tools, action_show_all_docks, action_hide_all_docks; - QString file_name; QList tbars; QList tdocks; QList actions_recent; QAction * action_clear_recent; QMenu * menu_recent; - SessionManager session; - bool isChanged, first_show; + bool is_changed; int max_recent; -private slots: - void changedDock(); - void sessionLoading(QPIConfig & conf) { loadingSession(conf); } - void sessionSaving(QPIConfig & conf) { savingSession(conf); } - void closeDock(int index); - void recentTriggered(); - public slots: void setMaxRecentItems(int mr); void changed() { setChanged(true); } @@ -152,6 +140,11 @@ public slots: bool saveAsFile(); void clearRecent(); +private slots: + void changedDock(); + void closeDock(int index); + void recentTriggered(); + signals: }; diff --git a/libs/application/lang/qad_application_en.ts b/libs/application/lang/qad_application_en.ts index cc85e91..6fc6ed3 100644 --- a/libs/application/lang/qad_application_en.ts +++ b/libs/application/lang/qad_application_en.ts @@ -9,93 +9,121 @@ - + Versions - + Build - + Authors - + About Qt... - + OK - + About + + EDockWidget + + + Dock + + + + + Undock + + + + + Show normal + + + + + Maximize + + + + + Hide + + + EMainWindow - - + + Clear recent list - - - - + + + + Show all - - - - + + + + Hide all - + Toolbars - + Docks - + Select file to open - + Select files to open - + Save changes%1? - + in - + Select file to save @@ -103,8 +131,8 @@ HistoryView - - + + History cleared @@ -117,26 +145,27 @@ - - - + + + Clear - - + + Select All - - + + Copy - + + All diff --git a/libs/application/lang/qad_application_ru.ts b/libs/application/lang/qad_application_ru.ts index bb4ba21..04c3ea5 100644 --- a/libs/application/lang/qad_application_ru.ts +++ b/libs/application/lang/qad_application_ru.ts @@ -9,93 +9,121 @@ - О программе - + Versions Версии - + Build Сборка - + Authors Авторы - + About Qt... О Qt ... - + OK - + About О программе + + EDockWidget + + + Dock + Закрепить + + + + Undock + Открепить + + + + Show normal + Восстановить + + + + Maximize + Развернуть + + + + Hide + Скрыть + + EMainWindow - - + + Clear recent list Очистить список недавних - - - - + + + + Show all Показать все - - - - + + + + Hide all Скрыть все - + Toolbars Панели инструментов - + Docks Окна - + Select file to open Выбрать файл для открытия - + Select files to open Выберите файлы для открытия - + Save changes%1? Сохранить изменения%1? - + in в - + Select file to save Выберите файл для сохранения @@ -103,8 +131,8 @@ HistoryView - - + + History cleared История очищена @@ -117,26 +145,27 @@ Категория: - - - + + + Clear Очистить - - + + Select All Выделить всё - - + + Copy Копировать - + + All Все diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index 8e00dba..5297c48 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -1252,24 +1252,31 @@ void Graphic::setCurrentGraphic(int arg) { } -void Graphic::setGraphicsCount(int arg, bool update) { - if (arg < 0) return; - while (graphics.size() < arg) { #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - graphics.append( - GraphicType(tr("y(x)"), - QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - QRandomGenerator::global()->generate() % 115))); +# define _G_QRAND_ QRandomGenerator::global()->generate() #else - graphics.append(GraphicType(tr("y(x)"), QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - qrand() % 115))); +# define _G_QRAND_ qrand() #endif + +void Graphic::setGraphicsCount(int count, bool update) { + if (count < 0) return; + while (graphics.size() < count) { + GraphicType gt(tr("y(x)")); + if (loaded_configs.size() > graphics.size()) + gt = loaded_configs[graphics.size()]; + else + gt.pen.setColor(QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - _G_QRAND_ % 115)); + graphics.append(gt); } - while (graphics.size() > arg) { + while (graphics.size() > count) { delete graphics.back().pb; graphics.pop_back(); } if (update) updateLegend(); } +#undef _G_QRAND_ + void Graphic::removeGraphic(int arg, bool update) { if (arg < 0 || arg >= graphics.size()) return; @@ -2309,6 +2316,10 @@ void Graphic::on_graphic_buttonConfigure_clicked() { setGridEnabled(conf->ui->groupGrid->isChecked()); updateLegend(); repaintCanvas(); + for (int i = 0; i < qMin(graphics.size(), loaded_configs.size()); ++i) { + loaded_configs[i] = graphics[i]; + loaded_configs[i].removeData(); + } } @@ -2702,6 +2713,9 @@ void Graphic::load(QByteArray ba) { setLegendVisible(a); } break; } + loaded_configs = graphics; + for (auto & i: loaded_configs) + i.removeData(); if (has_opengl != isOGL) setOpenGL(has_opengl); updateLegend(); repaintCanvas(true); diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 1efacb8..0def15d 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -442,7 +442,7 @@ protected: QBrush selbrush; QPen grid_pen, selpen; QColor back_color, text_color; - QVector graphics; + QVector graphics, loaded_configs; int curGraphic; GraphicAction curaction, prevaction; QRectF grect, selrect, limit_, def_rect; diff --git a/libs/graphic/graphic_conf.cpp b/libs/graphic/graphic_conf.cpp index cbf86d4..2d6c255 100644 --- a/libs/graphic/graphic_conf.cpp +++ b/libs/graphic/graphic_conf.cpp @@ -3,6 +3,38 @@ #include "qad_types.h" #include "ui_graphic_conf.h" +// GraphicType + +GraphicType::GraphicType(QString name_, QColor color, Qt::PenStyle style, double width, bool visible_) { + pen.setColor(color); + pen.setStyle(style); + lines = true; + points = false; + fill = false; + fill_color = Qt::yellow; + if (qRound(width) == width) + pen.setWidth(qRound(width)); + else + pen.setWidthF(width); + pen.setWidth(1); + pen.setCosmetic(true); + max_x = 0.; + name = name_; + visible = visible_; + pointWidth = 2.; + pb = new QCheckBox(name); +} + + +void GraphicType::removeData() { + polyline.clear(); + polyline_pause.clear(); + _lod.clear(); + _lod_pause.clear(); +} + + +// GraphicConf GraphicConf::GraphicConf(QVector & graphics_, QWidget * parent): QDialog(parent), graphics(graphics_) { ui = new Ui::GraphicConf(); diff --git a/libs/graphic/graphic_conf.h b/libs/graphic/graphic_conf.h index a6a6624..fe9b7d0 100644 --- a/libs/graphic/graphic_conf.h +++ b/libs/graphic/graphic_conf.h @@ -35,28 +35,11 @@ class GraphicConf; struct QAD_GRAPHIC_EXPORT GraphicType { GraphicType(QString name_ = "y(x)", - QColor color = Qt::red, - Qt::PenStyle style = Qt::SolidLine, - double width = 0., - bool visible_ = true) { - pen.setColor(color); - pen.setStyle(style); - lines = true; - points = false; - fill = false; - fill_color = Qt::yellow; - if (qRound(width) == width) - pen.setWidth(qRound(width)); - else - pen.setWidthF(width); - pen.setWidth(1); - pen.setCosmetic(true); - max_x = 0.; - name = name_; - visible = visible_; - pointWidth = 2.; - pb = new QCheckBox(name); - } + QColor color = Qt::red, + Qt::PenStyle style = Qt::SolidLine, + double width = 0., + bool visible_ = true); + void removeData(); //~GraphicType() {delete pb;} QString name; QPolygonF polyline;