Skip to content

Commit

Permalink
dont open elems catalog in view mode, use custom elems tool instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Chunosov committed Jan 13, 2020
1 parent c4dbac0 commit 11a0283
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 64 deletions.
2 changes: 2 additions & 0 deletions rezonator.pro
Expand Up @@ -57,6 +57,7 @@ HEADERS += \
src/CalcManager.h \
src/CalculatorWindow.h \
src/CustomElemsManager.h \
src/CustomElemsWindow.h \
src/CustomPrefs.h \
src/ElementPropsDialog.h \
src/ElementsCatalogDialog.h \
Expand Down Expand Up @@ -174,6 +175,7 @@ SOURCES += \
src/CalcManager.cpp \
src/CalculatorWindow.cpp \
src/CustomElemsManager.cpp \
src/CustomElemsWindow.cpp \
src/CustomPrefs.cpp \
src/ElementPropsDialog.cpp \
src/ElementsCatalogDialog.cpp \
Expand Down
52 changes: 52 additions & 0 deletions src/CustomElemsWindow.cpp
@@ -0,0 +1,52 @@
#include "CustomElemsWindow.h"

#include "CustomPrefs.h"
#include "helpers/OriWindows.h"

#include <QIcon>

namespace {

CustomElemsWindow* __instance = nullptr;

} // namespace

void CustomElemsWindow::showWindow()
{
if (!__instance)
__instance = new CustomElemsWindow;
__instance->show();
__instance->activateWindow();
}

CustomElemsWindow::CustomElemsWindow(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(tr("Custom Elements"));
setWindowIcon(QIcon(":/window_icons/catalog"));

restoreState();
Ori::Wnd::moveToScreenCenter(this);
}

CustomElemsWindow::~CustomElemsWindow()
{
storeState();
__instance = nullptr;
}

void CustomElemsWindow::restoreState()
{
QJsonObject root = CustomDataHelpers::loadCustomData("elems");

CustomDataHelpers::restoreWindowSize(root, this, 750, 400);
}

void CustomElemsWindow::storeState()
{
QJsonObject root;
root["window_width"] = width();
root["window_height"] = height();

CustomDataHelpers::saveCustomData(root, "elems");
}
21 changes: 21 additions & 0 deletions src/CustomElemsWindow.h
@@ -0,0 +1,21 @@
#ifndef CUSTOM_ELEMS_WINDOW_H
#define CUSTOM_ELEMS_WINDOW_H

#include <QWidget>

class CustomElemsWindow : public QWidget
{
Q_OBJECT

public:
explicit CustomElemsWindow(QWidget *parent = nullptr);
~CustomElemsWindow() override;

static void showWindow();

private:
void restoreState();
void storeState();
};

#endif // CUSTOM_ELEMS_WINDOW_H
48 changes: 9 additions & 39 deletions src/ElementsCatalogDialog.cpp
Expand Up @@ -20,17 +20,11 @@
#include <QTabWidget>
#include <QTextBrowser>

namespace Z {
namespace Dlgs {
static int __savedTabIndex = 0;

// TODO: ElementsCatalog should be QWidget, not QDialog.
// In CatalogMode_View mode it should be displayed as tool window (Qt::Tool),
// as this type of window is not overlapped by main window on MacOS.
// In CatalogMode_Selector it should be displayed via Ori::Dialog or like that.

Element* createElement()
Element* ElementsCatalogDialog::createElement()
{
ElementsCatalogDialog catalog(ElementsCatalogDialog::CatalogMode_Selector);
ElementsCatalogDialog catalog;
if (catalog.exec() != QDialog::Accepted)
return nullptr;

Expand All @@ -47,28 +41,7 @@ Element* createElement()
return newElem;
}

void showElementsCatalog()
{
auto catalog = new ElementsCatalogDialog(ElementsCatalogDialog::CatalogMode_View);
// NOTE: on MacOS popup window can by overlapped by main window
// It seems be normal for MacOS, e.g. file info window is opened by Finder
// and can be overlapped by Finder main window so we can't activate it again.
catalog->show();
}

} // namespace Dlgs
} // namespace Z

//-----------------------------------------------------------------------------
// ElementsCatalogDialog
//-----------------------------------------------------------------------------

namespace {
int __savedTabIndex = 0;
}

ElementsCatalogDialog::ElementsCatalogDialog(CatalogMode mode, QWidget *parent)
: RezonatorDialog(mode == CatalogMode_View ? OmitButtonsPanel : DontDeleteOnClose, parent)
ElementsCatalogDialog::ElementsCatalogDialog(QWidget *parent): RezonatorDialog(DontDeleteOnClose, parent)
{
setTitleAndIcon(tr("Elements Catalog"), ":/window_icons/catalog");
setObjectName("ElementsCatalogDialog");
Expand All @@ -88,20 +61,17 @@ ElementsCatalogDialog::ElementsCatalogDialog(CatalogMode mode, QWidget *parent)
_previewHtml->document()->setDefaultStyleSheet(Z::Gui::reportStyleSheet());
}

connect(_categoryTabs, SIGNAL(currentChanged(int)), this, SLOT(categorySelected(int)));
connect(_categoryTabs, &QTabWidget::currentChanged, this, &ElementsCatalogDialog::categorySelected);
mainLayout()->addWidget(_categoryTabs);

// preview
_previewSvg = new Ori::Widgets::SvgView(QString());

// element list
_elementsList = new ElementTypesListView;
connect(_elementsList, &ElementTypesListView::elementSelected, this, &ElementsCatalogDialog::loadDrawing);
if (mode == CatalogMode_Selector)
{
connect(_elementsList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(accept()));
connect(_elementsList, SIGNAL(enterPressed()), this, SLOT(accept()));
}
connect(_elementsList, &ElementTypesListView::elementSelected, this, &ElementsCatalogDialog::updatePreview);
connect(_elementsList, &ElementTypesListView::itemDoubleClicked, this, &ElementsCatalogDialog::accept);
connect(_elementsList, &ElementTypesListView::enterPressed, this, &ElementsCatalogDialog::accept);

_preview = new QStackedWidget;
_preview->addWidget(_previewSvg);
Expand Down Expand Up @@ -176,7 +146,7 @@ static QString makeCustomElemPreview(Element* elem)
return QString();
}

void ElementsCatalogDialog::loadDrawing(Element* elem)
void ElementsCatalogDialog::updatePreview(Element* elem)
{
if (_categoryTabs->currentIndex() == _customElemsTab)
_previewHtml->setHtml(makeCustomElemPreview(elem));
Expand Down
22 changes: 4 additions & 18 deletions src/ElementsCatalogDialog.h
Expand Up @@ -24,23 +24,19 @@ class ElementsCatalogDialog : public RezonatorDialog
Q_OBJECT

public:
enum CatalogMode
{
CatalogMode_Selector,
CatalogMode_View
};

struct Selection
{
Element* elem;
bool isCustom;
};

ElementsCatalogDialog(CatalogMode mode, QWidget* parent = nullptr);
ElementsCatalogDialog(QWidget* parent = nullptr);
~ElementsCatalogDialog() override;

Selection selection() const;

static Element* createElement();

protected:
QSize prefferedSize() const override { return QSize(600, 400); }

Expand All @@ -54,18 +50,8 @@ class ElementsCatalogDialog : public RezonatorDialog
int _customElemsTab = -1;
Schema *_customElems = nullptr;

private slots:
void categorySelected(int index);
void loadDrawing(Element *elem);
void updatePreview(Element *elem);
};


namespace Z {
namespace Dlgs {

Element* createElement();
void showElementsCatalog();

}}

#endif // ELEMENT_SELECTOR_H
9 changes: 5 additions & 4 deletions src/ProjectWindow.cpp
Expand Up @@ -4,6 +4,7 @@
#include "CalcManager.h"
#include "CalculatorWindow.h"
#include "CommonData.h"
#include "CustomElemsWindow.h"
#include "ElementsCatalogDialog.h"
#include "GaussCalculatorWindow.h"
#include "HelpSystem.h"
Expand Down Expand Up @@ -146,7 +147,7 @@ void ProjectWindow::createActions()
actnFuncBeamVariation = A_(tr("Beamsize Variation..."), _calculations, SLOT(funcBeamVariation()), ":/toolbar/func_beam_variation");
actnFuncBeamParamsAtElems = A_(tr("Beam Parameters at Elemens"), _calculations, SLOT(funcBeamParamsAtElems()), ":/toolbar/func_beamdata");

actnToolsCatalog = A_(tr("Elements Catalog"), this, SLOT(showElementsCatalog()), ":/toolbar/catalog");
actnToolsCustomElems = A_(tr("Custom Elements"), this, SLOT(showCustomElems()), ":/toolbar/catalog");
actnToolsGaussCalc = A_(tr("Gauss Calculator"), this, SLOT(showGaussCalculator()), ":/toolbar/gauss_calculator");
actnToolsCalc = A_(tr("Formula Calculator"), this, SLOT(showCalculator()), ":/window_icons/calculator");
actnToolFlipSchema = A_(tr("Flip Schema..."), this, SLOT(flipSchema()));
Expand Down Expand Up @@ -206,7 +207,7 @@ void ProjectWindow::createMenuBar()

menuTools = Ori::Gui::menu(tr("Tools", "Menu title"), this,
{ actnToolFlipSchema, nullptr, actnToolAdjust, nullptr,
actnToolsGaussCalc, actnToolsCalc, actnToolsCatalog, nullptr, actnToolSettings });
actnToolsGaussCalc, actnToolsCalc, actnToolsCustomElems, nullptr, actnToolSettings });

menuWindow = Ori::Gui::menu(tr("Window"), this,
{ actnWndSchema, actnWndParams, actnWndPumps, actnWndProtocol, nullptr,
Expand Down Expand Up @@ -444,9 +445,9 @@ void ProjectWindow::openSchemaExample()
//------------------------------------------------------------------------------
// Tools actions

void ProjectWindow::showElementsCatalog()
void ProjectWindow::showCustomElems()
{
Z::Dlgs::showElementsCatalog();
CustomElemsWindow::showWindow();
}

void ProjectWindow::showSettings()
Expand Down
4 changes: 2 additions & 2 deletions src/ProjectWindow.h
Expand Up @@ -71,7 +71,7 @@ class ProjectWindow : public QMainWindow, public SchemaToolWindow
*actnFuncCaustic, *actnFuncMultirangeCaustic, *actnFuncBeamVariation,
*actnFuncMultibeamCaustic, *actnFuncBeamParamsAtElems;

QAction *actnToolsGaussCalc, *actnToolsCatalog, *actnToolSettings,
QAction *actnToolsGaussCalc, *actnToolsCustomElems, *actnToolSettings,
*actnToolFlipSchema, *actnToolsCalc, *actnToolAdjust;

QAction *actnWndClose, *actnWndCloseAll, *actnWndTile, *actnWndCascade,
Expand Down Expand Up @@ -107,7 +107,7 @@ class ProjectWindow : public QMainWindow, public SchemaToolWindow
void shortcutEnterActivated();

private slots:
void showElementsCatalog();
void showCustomElems();
void showSettings();
void showProtocolWindow();
void showSchemaWindow();
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaViewWindow.cpp
Expand Up @@ -118,7 +118,7 @@ void SchemaViewWindow::rowDoubleClicked(Element *elem)

void SchemaViewWindow::actionElemAdd()
{
Element *elem = Z::Dlgs::createElement();
Element *elem = ElementsCatalogDialog::createElement();
if (elem)
schema()->insertElement(elem, _table->currentRow(), true);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
@@ -1,5 +1,6 @@
#include "CommonData.h"
#include "CalculatorWindow.h"
#include "CustomElemsWindow.h"
#include "GaussCalculatorWindow.h"
#include "ProjectOperations.h"
#include "ProjectWindow.h"
Expand Down Expand Up @@ -90,6 +91,11 @@ int main(int argc, char* argv[])
CalculatorWindow::showWindow();
return app.exec();
}
else if (toolName == "elems")
{
CustomElemsWindow::showWindow();
return app.exec();
}
else
{
#ifdef Q_OS_WIN
Expand Down

0 comments on commit 11a0283

Please sign in to comment.