[education/rkward] rkward: Now that the preview window is a plain widget, do away with the wrapper widget.
Thomas Friedrichsmeier
null at kde.org
Sat Jul 2 21:40:45 BST 2022
Git commit bffdcfc99676c61a78845bf71f3542bbfcda9fd8 by Thomas Friedrichsmeier.
Committed on 02/07/2022 at 20:39.
Pushed by tfry into branch 'master'.
Now that the preview window is a plain widget, do away with the wrapper widget.
M +44 -51 rkward/misc/rkxmlguipreviewarea.cpp
M +2 -6 rkward/misc/rkxmlguipreviewarea.h
M +1 -1 rkward/plugin/rkstandardcomponentgui.cpp
M +4 -5 rkward/windows/rkcommandeditorwindow.cpp
https://invent.kde.org/education/rkward/commit/bffdcfc99676c61a78845bf71f3542bbfcda9fd8
diff --git a/rkward/misc/rkxmlguipreviewarea.cpp b/rkward/misc/rkxmlguipreviewarea.cpp
index 56b16daf..d89192a4 100644
--- a/rkward/misc/rkxmlguipreviewarea.cpp
+++ b/rkward/misc/rkxmlguipreviewarea.cpp
@@ -59,10 +59,42 @@ private:
RKXMLGUIPreviewArea::RKXMLGUIPreviewArea (const QString &label, QWidget* parent) : QWidget (parent) {
RK_TRACE (PLUGIN);
- _label = label;
- wrapper_widget = nullptr;
current = nullptr;
+ menubar = nullptr;
+ builder = nullptr;
+ factory = nullptr;
+
+ QVBoxLayout *vl = new QVBoxLayout(this);
+ vl->setContentsMargins(0, 0, 0, 0);
+ QFrame *line = new QFrame();
+ line->setFrameShape(QFrame::HLine);
+ vl->addWidget(line);
+ QHBoxLayout *hl = new QHBoxLayout();
+ vl->addLayout(hl);
+ lab = new QLabel(label);
+ QFont fnt(lab->font());
+ fnt.setBold(true);
+ lab->setFont(fnt);
+ lab->setAlignment(Qt::AlignCenter);
+ QToolButton *tb = new QToolButton();
+ tb->setAutoRaise(true);
+ tb->setIcon(RKStandardIcons::getIcon(RKStandardIcons::ActionDelete));
+ connect(tb, &QAbstractButton::clicked, this, [this]() { hide(); emit previewClosed(this); });
+
+ QToolButton *menu_button = new QToolButton(this);
+ menu_button->setPopupMode(QToolButton::InstantPopup);
+ menu_button->setIcon(RKStandardIcons::getIcon(RKStandardIcons::ActionShowMenu));
+ menu_button->setMenu(menu = new QMenu(this));
+ connect(menu, &QMenu::aboutToShow, this, &RKXMLGUIPreviewArea::prepareMenu);
+
+ hl->addWidget(menu_button);
+ hl->addStretch();
+ hl->addWidget(lab);
+ hl->addWidget(tb);
+ hl->addStretch();
internal_layout = new QVBoxLayout(this);
+ vl->addLayout(internal_layout);
+
menubar = new QMenuBar(nullptr); // it is important that the menubar never is a child of the main window, not even indirectly! https://bugs.kde.org/show_bug.cgi?id=416911
builder = new RKXMLGUIPreviewBuilder(this, menubar);
factory = new KXMLGUIFactory(builder, this);
@@ -71,75 +103,36 @@ RKXMLGUIPreviewArea::RKXMLGUIPreviewArea (const QString &label, QWidget* parent)
RKXMLGUIPreviewArea::~RKXMLGUIPreviewArea () {
RK_TRACE (PLUGIN);
- if (current) {
+ if (current && factory) {
factory->removeClient(current);
current->setFactory (0);
}
- if (wrapper_widget) wrapper_widget->deleteLater();
delete menubar;
delete builder;
delete factory;
}
void RKXMLGUIPreviewArea::setLabel (const QString& label) {
- RK_TRACE (PLUGIN);
-
- if (label == _label) return;
- _label = label;
- if (wrapper_widget) {
- lab->setText (label);
- }
+ RK_TRACE(PLUGIN);
+ lab->setText(label);
}
-QWidget* RKXMLGUIPreviewArea::wrapperWidget () {
- if (wrapper_widget) return wrapper_widget;
-
- wrapper_widget = new QWidget ();
-
- QVBoxLayout *vl = new QVBoxLayout (wrapper_widget);
- vl->setContentsMargins (0, 0, 0, 0);
- QFrame *line = new QFrame (wrapper_widget);
- line->setFrameShape (QFrame::HLine);
- vl->addWidget (line);
- QHBoxLayout *hl = new QHBoxLayout ();
- vl->addLayout (hl);
- lab = new QLabel (_label, wrapper_widget);
- QFont fnt (lab->font ());
- fnt.setBold (true);
- lab->setFont (fnt);
- lab->setAlignment (Qt::AlignCenter);
- QToolButton *tb = new QToolButton (wrapper_widget);
- tb->setAutoRaise (true);
- tb->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDelete));
- connect (tb, &QAbstractButton::clicked, this, [this]() { wrapper_widget->hide(); emit previewClosed(this); });
-
- QToolButton *menu_button = new QToolButton(this);
- menu_button->setPopupMode(QToolButton::InstantPopup);
- menu_button->setIcon(RKStandardIcons::getIcon(RKStandardIcons::ActionShowMenu));
- menu_button->setMenu(menu = new QMenu(wrapper_widget));
- connect(menu, &QMenu::aboutToShow, this, &RKXMLGUIPreviewArea::prepareMenu);
-
- hl->addWidget (menu_button);
- hl->addStretch ();
- hl->addWidget (lab);
- hl->addWidget (tb);
- hl->addStretch ();
-
- vl->addWidget(this);
- show ();
-
- return wrapper_widget;
+QString RKXMLGUIPreviewArea::label() const {
+ RK_TRACE(PLUGIN);
+ return lab->text();
}
void RKXMLGUIPreviewArea::setWindow(RKMDIWindow* window) {
+ RK_TRACE(PLUGIN);
+
if (current) {
factory->removeClient(current); // _always_ remove before adding, or the previous child will be leaked in the factory
}
window->setWindowStyleHint("preview");
current = window->getPart();
- factory->addClient(current);
internal_layout->addWidget(window);
- QList<QAction*> acts = wrapper_widget->actions();
+ factory->addClient(current);
+ QList<QAction*> acts = actions();
for (int i = 0; i < acts.size (); ++i) acts[i]->setShortcutContext(Qt::WidgetWithChildrenShortcut);
RKWorkplace::mainWorkplace()->setWindowNotManaged(window);
}
diff --git a/rkward/misc/rkxmlguipreviewarea.h b/rkward/misc/rkxmlguipreviewarea.h
index 565b1e35..846eef95 100644
--- a/rkward/misc/rkxmlguipreviewarea.h
+++ b/rkward/misc/rkxmlguipreviewarea.h
@@ -27,18 +27,14 @@ class RKXMLGUIPreviewArea : public QWidget {
public:
RKXMLGUIPreviewArea (const QString &label, QWidget* parent);
~RKXMLGUIPreviewArea ();
- /** Returns a wrapper widget (created on first call of this function) that contains this widget along with a caption (see setLabel()), menu button, and close button. */
- QWidget *wrapperWidget ();
- QString label () const { return _label; };
- void setLabel (const QString &label);
+ QString label() const;
+ void setLabel(const QString &label);
void setWindow(RKMDIWindow* window);
protected slots:
void prepareMenu ();
signals:
void previewClosed (RKXMLGUIPreviewArea *preview);
private:
- QWidget *wrapper_widget;
- QString _label;
QLabel *lab;
QMenu *menu;
QMenuBar *menubar;
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index 7263c62d..2b0e458a 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -241,7 +241,7 @@ void RKStandardComponentGUI::finalize () {
bool any_vpreview_visible = RKSettingsModulePlugins::showCodeByDefault ();
for (int i = 0; i < previews.size (); ++i) {
// Add preview to splitter. Also add a title bar to each preview.
- previews[i].widget = previews[i].preview_area->wrapperWidget ();
+ previews[i].widget = previews[i].preview_area;
connect (previews[i].preview_area, &RKXMLGUIPreviewArea::previewClosed, this, &RKStandardComponentGUI::previewCloseButtonClicked);
connect (previews[i].controller, &RKComponentPropertyBase::valueChanged, this, &RKStandardComponentGUI::previewVisibilityChanged);
if (!(previews[i].controller->boolValue ())) previews[i].widget->hide ();
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index b4315a68..8f47b5e2 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -247,9 +247,8 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl &_url,
layout->setContentsMargins (0, 0, 0, 0);
QSplitter* preview_splitter = new QSplitter (this);
preview_splitter->addWidget (m_view);
- QWidget *preview_widget = preview->wrapperWidget ();
- preview_splitter->addWidget (preview_widget);
- preview_widget->hide ();
+ preview_splitter->addWidget(preview);
+ preview->hide();
connect (m_doc, &KTextEditor::Document::documentSavedOrUploaded, this, &RKCommandEditorWindow::documentSaved);
layout->addWidget(preview_splitter);
@@ -568,7 +567,7 @@ void RKCommandEditorWindow::discardPreview () {
RK_TRACE (COMMANDEDITOR);
if (preview_dir) {
- preview->wrapperWidget ()->hide ();
+ preview->hide ();
preview_manager->setPreviewDisabled ();
RInterface::issueCommand (QString (".rk.killPreviewDevice(%1)\nrk.discard.preview.data (%1)").arg (RObject::rQuote(preview_manager->previewId ())), RCommand::App | RCommand::Sync);
delete preview_dir;
@@ -943,7 +942,7 @@ void RKCommandEditorWindow::doRenderPreview () {
RK_ASSERT (false);
}
- preview->wrapperWidget ()->show ();
+ preview->show ();
RCommand *rcommand = new RCommand (".rk.with.window.hints (local ({\n" + command + QStringLiteral ("}), \"\", ") + RObject::rQuote (preview_manager->previewId ()) + ", style=\"preview\")", RCommand::App);
preview_manager->setCommand (rcommand);
More information about the rkward-tracker
mailing list