Skip to content

Commit

Permalink
Make the drawing styles dialog non-modal (and clean up some dead code)
Browse files Browse the repository at this point in the history
Re: issue #264
  • Loading branch information
eteran committed Jan 15, 2021
1 parent aa203aa commit 504bc4a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/DialogDrawingStyles.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "Verbosity.h"
#include "ui_DialogDrawingStyles.h"

#include <QPointer>

#include <boost/optional.hpp>

class DialogSyntaxPatterns;
Expand Down Expand Up @@ -52,7 +54,7 @@ class DialogDrawingStyles final : public Dialog {
HighlightStyleModel *model_;
std::vector<HighlightStyle> &highlightStyles_;
QModelIndex deleted_;
DialogSyntaxPatterns *dialogSyntaxPatterns_;
QPointer<DialogSyntaxPatterns> dialogSyntaxPatterns_;
};

#endif
14 changes: 9 additions & 5 deletions src/DialogSyntaxPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* @param parent
* @param f
*/
DialogSyntaxPatterns::DialogSyntaxPatterns(MainWindow *window, Qt::WindowFlags f)
: Dialog(window, f), window_(window) {
DialogSyntaxPatterns::DialogSyntaxPatterns(QWidget *parent, Qt::WindowFlags f)
: Dialog(parent, f) {

ui.setupUi(this);
connectSlots();
Expand Down Expand Up @@ -277,9 +277,13 @@ void DialogSyntaxPatterns::buttonLanguageMode_clicked() {
void DialogSyntaxPatterns::buttonHighlightStyle_clicked() {
QString style = ui.comboHighlightStyle->currentText();
if (!style.isEmpty()) {
auto DrawingStyles = std::make_unique<DialogDrawingStyles>(this, Highlight::HighlightStyles, this);
DrawingStyles->setStyleByName(style);
DrawingStyles->exec();

if (!dialogDrawingStyles_) {
dialogDrawingStyles_ = new DialogDrawingStyles(this, Highlight::HighlightStyles, this);
}

dialogDrawingStyles_->setStyleByName(style);
dialogDrawingStyles_->show();
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/DialogSyntaxPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
#include "Verbosity.h"
#include "ui_DialogSyntaxPatterns.h"

#include <QPointer>

#include <boost/optional.hpp>
#include <memory>

class HighlightPattern;
class HighlightPatternModel;
class MainWindow;
class PatternSet;
class DialogDrawingStyles;

class DialogSyntaxPatterns final : public Dialog {
Q_OBJECT

public:
explicit DialogSyntaxPatterns(MainWindow *window, Qt::WindowFlags f = Qt::WindowFlags());
explicit DialogSyntaxPatterns(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~DialogSyntaxPatterns() override = default;

public:
Expand Down Expand Up @@ -71,7 +73,7 @@ private Q_SLOTS:
HighlightPatternModel *model_;
QModelIndex deleted_;
QString previousLanguage_;
MainWindow *window_;
QPointer<DialogDrawingStyles> dialogDrawingStyles_;
};

#endif
12 changes: 9 additions & 3 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6120,9 +6120,15 @@ MainWindow *MainWindow::fromDocument(const DocumentWidget *document) {
*/
void MainWindow::editHighlightStyles(const QString &initialStyle) {

auto DrawingStyles = std::make_unique<DialogDrawingStyles>(nullptr, Highlight::HighlightStyles, this);
DrawingStyles->setStyleByName(initialStyle);
DrawingStyles->exec();
if (!dialogDrawingStyles_) {
dialogDrawingStyles_ = new DialogDrawingStyles(nullptr, Highlight::HighlightStyles, this);
}

dialogDrawingStyles_->setStyleByName(initialStyle);

// TODO(eteran): do we want to take any measures to prevent
// more than one of these being shown?
dialogDrawingStyles_->show();
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DialogReplace;
class DialogShellMenu;
class DialogWindowBackgroundMenu;
class DialogSyntaxPatterns;
class DialogDrawingStyles;
class DocumentWidget;
class TextArea;
struct MenuData;
Expand Down Expand Up @@ -444,6 +445,7 @@ public Q_SLOTS:
QPointer<DialogColors> dialogColors_;
QPointer<DialogWindowBackgroundMenu> dialogWindowBackgroundMenu_;
QPointer<DialogSyntaxPatterns> dialogSyntaxPatterns_;
QPointer<DialogDrawingStyles> dialogDrawingStyles_;
QPointer<TextArea> lastFocus_;

private:
Expand Down

0 comments on commit 504bc4a

Please sign in to comment.