New Dialog widget base class and ConfirmationDialog widget
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include "ConfirmationDialog.hpp"
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
ConfirmationDialog::ConfirmationDialog(
|
||||
const QString& windowTitle,
|
||||
const QString& text,
|
||||
const std::optional<QString>& confirmationButtonText,
|
||||
const std::optional<QString>& cancelButtonText,
|
||||
QWidget* parent
|
||||
)
|
||||
: Dialog(windowTitle, text, parent)
|
||||
{
|
||||
this->confirmButton->setStyleName("primary");
|
||||
|
||||
this->addActionButton(this->confirmButton);
|
||||
this->addActionButton(this->cancelButton);
|
||||
|
||||
this->confirmButton->setText(confirmationButtonText.value_or("Proceed"));
|
||||
this->cancelButton->setText(cancelButtonText.value_or("Cancel"));
|
||||
|
||||
QObject::connect(this->confirmButton, &QPushButton::clicked, this, [this] {
|
||||
this->close();
|
||||
emit this->confirmed();
|
||||
});
|
||||
|
||||
QObject::connect(this->cancelButton, &QPushButton::clicked, this, [this] {
|
||||
this->close();
|
||||
emit this->aborted();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <QString>
|
||||
|
||||
#include "Dialog/Dialog.hpp"
|
||||
#include "PushButton.hpp"
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
class ConfirmationDialog: public Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfirmationDialog(
|
||||
const QString& windowTitle,
|
||||
const QString& text,
|
||||
const std::optional<QString>& confirmationButtonText,
|
||||
const std::optional<QString>& cancelButtonText,
|
||||
QWidget* parent = nullptr
|
||||
);
|
||||
|
||||
signals:
|
||||
void confirmed();
|
||||
void aborted();
|
||||
|
||||
protected:
|
||||
PushButton* confirmButton = new PushButton(this);
|
||||
PushButton* cancelButton = new PushButton(this);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "Dialog.hpp"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp"
|
||||
#include "src/Services/PathService.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
using Bloom::Exceptions::Exception;
|
||||
|
||||
Dialog::Dialog(
|
||||
const QString& windowTitle,
|
||||
const QString& text,
|
||||
QWidget* parent
|
||||
)
|
||||
: QDialog(parent)
|
||||
{
|
||||
this->setObjectName("dialog");
|
||||
this->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
this->setWindowTitle(windowTitle);
|
||||
|
||||
auto dialogUiFile = QFile(
|
||||
QString::fromStdString(Services::PathService::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/UiFiles/Dialog.ui"
|
||||
)
|
||||
);
|
||||
|
||||
auto dialogStylesheet = QFile(
|
||||
QString::fromStdString(Services::PathService::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Stylesheets/Dialog.qss"
|
||||
)
|
||||
);
|
||||
|
||||
if (!dialogUiFile.open(QFile::ReadOnly)) {
|
||||
throw Exception("Failed to open Dialog UI file");
|
||||
}
|
||||
|
||||
if (!dialogStylesheet.open(QFile::ReadOnly)) {
|
||||
throw Exception("Failed to open Dialog stylesheet file");
|
||||
}
|
||||
|
||||
this->setStyleSheet(dialogStylesheet.readAll());
|
||||
|
||||
auto uiLoader = UiLoader(this);
|
||||
this->container = uiLoader.load(&dialogUiFile, this);
|
||||
|
||||
this->textLabel = this->container->findChild<Label*>("text-label");
|
||||
this->actionLayout = this->container->findChild<QHBoxLayout*>("actions-layout");
|
||||
|
||||
this->container->setContentsMargins(15, 10, 15, 15);
|
||||
|
||||
this->textLabel->setTextFormat(Qt::TextFormat::RichText);
|
||||
this->textLabel->setText(text);
|
||||
this->setMinimumSize(500, 150);
|
||||
}
|
||||
|
||||
void Dialog::showEvent(QShowEvent* event) {
|
||||
const auto containerSize = this->container->sizeHint();
|
||||
const auto windowSize = QSize(
|
||||
std::max(containerSize.width(), 500),
|
||||
std::max(containerSize.height(), 100)
|
||||
);
|
||||
|
||||
this->setFixedSize(windowSize);
|
||||
this->container->setFixedSize(windowSize);
|
||||
}
|
||||
|
||||
void Dialog::addActionButton(QPushButton* button) {
|
||||
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
this->actionLayout->insertWidget(1, button);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QShowEvent>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
class Dialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Dialog(
|
||||
const QString& windowTitle,
|
||||
const QString& text,
|
||||
QWidget* parent
|
||||
);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void addActionButton(QPushButton* button);
|
||||
|
||||
private:
|
||||
QWidget* container = nullptr;
|
||||
Label* textLabel = nullptr;
|
||||
QHBoxLayout* actionLayout = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="40"
|
||||
height="44"
|
||||
viewBox="0 0 10.583333 11.641666"
|
||||
version="1.1"
|
||||
id="svg974"
|
||||
sodipodi:docname="icon.svg"
|
||||
inkscape:version="1.0.1 (1.0.1+r75)">
|
||||
<defs
|
||||
id="defs968" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#343532"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="2.1160714"
|
||||
inkscape:cx="-130.38062"
|
||||
inkscape:cy="-2.8237951"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer2"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:snap-page="true"
|
||||
inkscape:window-width="3440"
|
||||
inkscape:window-height="1353"
|
||||
inkscape:window-x="2560"
|
||||
inkscape:window-y="34"
|
||||
inkscape:window-maximized="1"
|
||||
fit-margin-top="6"
|
||||
fit-margin-left="6"
|
||||
fit-margin-right="6"
|
||||
fit-margin-bottom="6"
|
||||
lock-margins="true"
|
||||
inkscape:snap-object-midpoints="true"
|
||||
inkscape:snap-smooth-nodes="true"
|
||||
inkscape:snap-bbox="true"
|
||||
inkscape:snap-bbox-edge-midpoints="true"
|
||||
inkscape:snap-bbox-midpoints="true"
|
||||
inkscape:bbox-nodes="true" />
|
||||
<metadata
|
||||
id="metadata971">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(1.3229167,1.0583334)" />
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer2"
|
||||
inkscape:label="Layer 2">
|
||||
<rect
|
||||
style="opacity:1;fill:#7f7f7e;fill-opacity:1;stroke-width:0.2144"
|
||||
id="rect882"
|
||||
width="9.5249996"
|
||||
height="10.583333"
|
||||
x="0.52916664"
|
||||
y="0.52916658" />
|
||||
<rect
|
||||
style="opacity:1;fill:#373835;fill-opacity:0.996078;stroke-width:0.21603"
|
||||
id="rect835"
|
||||
width="1.5875"
|
||||
height="4.2333331"
|
||||
x="4.4979162"
|
||||
y="2.6458333" />
|
||||
<rect
|
||||
style="opacity:1;fill:#373835;fill-opacity:0.996078;stroke-width:0.132291"
|
||||
id="rect835-3"
|
||||
width="1.5875"
|
||||
height="1.5875"
|
||||
x="4.4979162"
|
||||
y="7.6729188" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,7 @@
|
||||
#dialog {
|
||||
background-color: #373835;
|
||||
}
|
||||
|
||||
#text-label {
|
||||
font-size: 14px;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<widget class="QWidget" name="container">
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="SvgWidget" name="icon">
|
||||
<property name="svgFilePath">
|
||||
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Images/icon.svg</string>
|
||||
</property>
|
||||
<property name="containerHeight">
|
||||
<number>44</number>
|
||||
</property>
|
||||
<property name="containerWidth">
|
||||
<number>40</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontal-spacer">
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>10</width>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item alignment="Qt::AlignVCenter">
|
||||
<widget class="Label" name="text-label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<enum>Qt::AlignLeft</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="vertical-spacer">
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item alignment="Qt::AlignLeft">
|
||||
<spacer name="vertical-spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="actions-layout">
|
||||
<property name="spacing">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontal-spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</ui>
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
/**
|
||||
* @deprecated
|
||||
* TODO: Bin this. Replace all usages with Bloom::Widgets::Dialog.
|
||||
*/
|
||||
class ErrorDialogue: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Reference in New Issue
Block a user