Skip to content

Commit

Permalink
修改 guiplugin;
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed Apr 19, 2024
1 parent a020ddc commit abb0604
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 128 deletions.
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CURRENT_PLATFORM "-64")
set(BITS "64")
else()
set(CURRENT_PLATFORM "-32")
set(BITS "32")
endif()

message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
message(STATUS "Current Platform is ${BITS} bits.")

# 设定可执行二进制文件的目录
set(EXECUTABLE_OUTPUT_PATH
${PROJECT_SOURCE_DIR}/bin${CURRENT_PLATFORM}/${CMAKE_BUILD_TYPE}) # 源文件目录
# 设定存放编译出来的库文件的目录
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin${CURRENT_PLATFORM}/libs)
# 并且把该目录设为连接目录
${PROJECT_SOURCE_DIR}/bin-${BITS}/${CMAKE_BUILD_TYPE})
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin-${BITS}/libs)
link_directories(${LIBRARY_OUTPUT_PATH})

include_directories(${PROJECT_SOURCE_DIR})
Expand Down
8 changes: 5 additions & 3 deletions src/gui/commonwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ CommonWidget::CommonWidget(QWidget *parent)
QMetaObject::invokeMethod(this, &CommonWidget::onShowNormal, Qt::QueuedConnection);
}

CommonWidget::~CommonWidget() {}
CommonWidget::~CommonWidget() = default;

void CommonWidget::setRestoreMaxButtonVisible(bool visible)
{
Expand Down Expand Up @@ -252,8 +252,10 @@ void CommonWidget::onShowNormal()
d_ptr->shadowPadding,
d_ptr->shadowPadding);
showNormal();
d_ptr->maxButton->show();
d_ptr->restoreButton->hide();
if (d_ptr->maxButton->isVisible() || d_ptr->restoreButton->isVisible()) {
d_ptr->maxButton->show();
d_ptr->restoreButton->hide();
}
}

void CommonWidget::mousePressEvent(QMouseEvent *event)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/commonwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class GUI_EXPORT CommonWidget : public QWidget
explicit CommonWidget(QWidget *parent = nullptr);
~CommonWidget() override;

void setRestoreMaxButtonVisible(bool);
void setMinButtonVisible(bool);
void setRestoreMaxButtonVisible(bool visible);
void setMinButtonVisible(bool visible);

void setTitle(const QString &title);
void setIcon(const QIcon &icon);
Expand Down
8 changes: 5 additions & 3 deletions src/gui/dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ namespace GUI {
class Dialog::DialogPrivate
{
public:
DialogPrivate(Dialog *q)
explicit DialogPrivate(Dialog *q)
: q_ptr(q)
{}

Dialog *q_ptr;

QEventLoop loop;
Dialog::ExecFlags flag = Dialog::ExecFlags::Close;
};
Expand All @@ -29,9 +31,9 @@ Dialog::Dialog(QWidget *parent)
resize(600, 370);
}

Dialog::~Dialog() {}
Dialog::~Dialog() = default;

int Dialog::exec()
auto Dialog::exec() -> int
{
#ifdef Q_OS_LINUX
auto widget = parentWidget();
Expand Down
70 changes: 28 additions & 42 deletions src/gui/messbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class MessBox::MessBoxPrivate
explicit MessBoxPrivate(MessBox *q)
: q_ptr(q)
{
iconLabel = new QLabel(q_ptr);
iconButton = new QToolButton(q_ptr);
iconButton->setIconSize({48, 48});
iconButton->setObjectName("IconButton");
messageLabel = new QLabel(q_ptr);
messageLabel->setObjectName("MessageLabel");
messageLabel->setWordWrap(true);
messageLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
closeButton = new QPushButton(QCoreApplication::translate("MessBoxPrivate", "Close"), q_ptr);
closeButton->setObjectName("BlueButton");
yesButton = new QPushButton(QCoreApplication::translate("MessBoxPrivate", "Yes"), q_ptr);
Expand All @@ -24,41 +27,26 @@ class MessBox::MessBoxPrivate

void setupUI()
{
auto *hLayout = new QHBoxLayout;
hLayout->setSpacing(20);
hLayout->addSpacerItem(
new QSpacerItem(20, 10, QSizePolicy::Maximum, QSizePolicy::Expanding));
hLayout->addWidget(iconLabel);
hLayout->addWidget(messageLabel);
hLayout->addSpacerItem(
new QSpacerItem(20, 10, QSizePolicy::Maximum, QSizePolicy::Expanding));

auto *btnWidget = new QWidget(q_ptr);
btnWidget->setObjectName("MessBtnWidget");
auto *btnLayout = new QHBoxLayout(btnWidget);
btnLayout->setContentsMargins(10, 5, 20, 5);
btnLayout->setSpacing(5);
btnLayout->addStretch();
btnLayout->addWidget(yesButton);
btnLayout->addWidget(noButton);
btnLayout->addWidget(closeButton);

yesButton->hide();
noButton->hide();
closeButton->hide();

auto *widget = new QWidget(q_ptr);
auto *layout = new QVBoxLayout(widget);
layout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(hLayout);
layout->addWidget(btnWidget);
layout->setContentsMargins(20, 40, 20, 20);
layout->setSpacing(10);
layout->addWidget(iconButton, 0, Qt::AlignCenter);
layout->addWidget(messageLabel);
layout->addWidget(yesButton);
layout->addWidget(noButton);
layout->addWidget(closeButton);

q_ptr->setCentralWidget(widget);

yesButton->hide();
noButton->hide();
closeButton->hide();
}

MessBox *q_ptr;

QLabel *iconLabel;
QToolButton *iconButton;
QLabel *messageLabel;
QPushButton *yesButton;
QPushButton *noButton;
Expand All @@ -69,19 +57,17 @@ MessBox::MessBox(QWidget *parent)
: Dialog(parent)
, d_ptr(new MessBoxPrivate(this))
{
setMinButtonVisible(false);
setRestoreMaxButtonVisible(false);
d_ptr->setupUI();
buildConnect();
resize(400, 250);
resize(300, 450);
}

MessBox::~MessBox() = default;

auto MessBox::Info(QWidget *parent, const QString &msg, MessButton button) -> int
{
MessBox messBox(parent);
messBox.setIconLabelObjectName("InfoLabel");
messBox.setIcon(messBox.style()->standardIcon(QStyle::SP_MessageBoxInformation));
messBox.setMessage(msg);
switch (button) {
case YesAndNoButton: messBox.setYesAndNoButtonVisible(true); break;
Expand All @@ -94,7 +80,7 @@ auto MessBox::Info(QWidget *parent, const QString &msg, MessButton button) -> in
auto MessBox::Warning(QWidget *parent, const QString &msg, MessButton button) -> int
{
MessBox messBox(parent);
messBox.setIconLabelObjectName("WarningLabel");
messBox.setIcon(messBox.style()->standardIcon(QStyle::SP_MessageBoxWarning));
messBox.setMessage(msg);
switch (button) {
case YesAndNoButton: messBox.setYesAndNoButtonVisible(true); break;
Expand All @@ -104,25 +90,25 @@ auto MessBox::Warning(QWidget *parent, const QString &msg, MessButton button) ->
return messBox.exec();
}

void MessBox::setMessage(const QString &msg)
void MessBox::setIcon(const QIcon &icon)
{
d_ptr->messageLabel->setText(msg);
d_ptr->iconButton->setIcon(icon);
}

void MessBox::setIconLabelObjectName(const QString &objectName)
void MessBox::setMessage(const QString &msg)
{
d_ptr->iconLabel->setObjectName(objectName);
d_ptr->messageLabel->setText(msg);
}

void MessBox::setYesAndNoButtonVisible(bool state)
void MessBox::setYesAndNoButtonVisible(bool visible)
{
d_ptr->yesButton->setVisible(state);
d_ptr->noButton->setVisible(state);
d_ptr->yesButton->setVisible(visible);
d_ptr->noButton->setVisible(visible);
}

void MessBox::setCloseButtonVisible(bool state)
void MessBox::setCloseButtonVisible(bool visible)
{
d_ptr->closeButton->setVisible(state);
d_ptr->closeButton->setVisible(visible);
}

void MessBox::buildConnect()
Expand Down
8 changes: 4 additions & 4 deletions src/gui/messbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class GUI_EXPORT MessBox : public Dialog
static auto Info(QWidget *parent, const QString &msg, MessButton button = CloseButton) -> int;
static auto Warning(QWidget *parent, const QString &msg, MessButton button) -> int;

void setMessage(const QString &);
void setIconLabelObjectName(const QString &);
void setIcon(const QIcon &icon);
void setMessage(const QString &msg);

void setYesAndNoButtonVisible(bool);
void setCloseButtonVisible(bool);
void setYesAndNoButtonVisible(bool visible);
void setCloseButtonVisible(bool visible);

private:
void buildConnect();
Expand Down
57 changes: 53 additions & 4 deletions src/plugins/guiplugin/guiwidget.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "guiwidget.hpp"

#include <gui/messbox.h>

#include <QtWidgets>

namespace Plugin {
Expand All @@ -14,7 +16,7 @@ void GuiWidget::setupUI()
{
auto *layout = new QVBoxLayout(this);
layout->addWidget(createButtonGroup());
layout->addWidget(createBoxGroup());
layout->addWidget(createInputGroup());
layout->addWidget(createBarGroup());
}

Expand All @@ -30,9 +32,17 @@ auto GuiWidget::createButtonGroup() -> QGroupBox *
auto *checkBox = new QCheckBox(tr("Check"), this);
checkBox->setChecked(true);

connect(button, &QPushButton::clicked, this, [&] {
GUI::MessBox::Info(this, tr("This is an info message."), GUI::MessBox::YesAndNoButton);
});
connect(blueButton, &QPushButton::clicked, this, [&] {
GUI::MessBox::Warning(this, tr("This is a warning message."), GUI::MessBox::CloseButton);
});
grayButton->setMenu(createMenu());

auto *groupBox = new QGroupBox(tr("Buttons"), this);
auto *layout = new QHBoxLayout(groupBox);
layout->setSpacing(20);
layout->setSpacing(30);
layout->addWidget(button);
layout->addWidget(blueButton);
layout->addWidget(grayButton);
Expand All @@ -44,7 +54,7 @@ auto GuiWidget::createButtonGroup() -> QGroupBox *
return groupBox;
}

auto GuiWidget::createBoxGroup() -> QGroupBox *
auto GuiWidget::createInputGroup() -> QGroupBox *
{
auto *spinBox = new QSpinBox(this);
spinBox->setRange(0, 100);
Expand All @@ -56,11 +66,23 @@ auto GuiWidget::createBoxGroup() -> QGroupBox *
}
comboBox->setCurrentText("6");

auto *groupBox = new QGroupBox(tr("Boxes"), this);
auto *lineEdit = new QLineEdit(this);
lineEdit->setPlaceholderText("Text");
lineEdit->setClearButtonEnabled(true);

auto *lineEdit2 = new QLineEdit(this);
lineEdit2->setPlaceholderText("Password");
lineEdit2->setText("Password");
lineEdit2->setEchoMode(QLineEdit::Password);

auto *groupBox = new QGroupBox(tr("Inputs"), this);
auto *layout = new QHBoxLayout(groupBox);
layout->setSpacing(20);
layout->addWidget(spinBox);
layout->addWidget(comboBox);
layout->addWidget(lineEdit);
layout->addWidget(lineEdit2);
layout->addWidget(new QDial(this));

return groupBox;
}
Expand All @@ -86,4 +108,31 @@ auto GuiWidget::createBarGroup() -> QGroupBox *
return groupBox;
}

auto GuiWidget::createMenu() -> QMenu *
{
auto *menu = new QMenu(this);
menu->addAction(tr("Action 1"));
auto *action = menu->addAction(tr("Action 2"));
action->setCheckable(true);
action = menu->addAction(tr("Action 3"));
action->setCheckable(true);
action->setChecked(true);
menu->addSeparator();
menu->addAction(style()->standardIcon(QStyle::SP_DesktopIcon), tr("Action 4"));
menu->addAction(style()->standardIcon(QStyle::SP_TrashIcon), tr("Action 5"));

auto *submenu = menu->addMenu(tr("Submenu"));
submenu->addAction(tr("Action 1"));
action = submenu->addAction(tr("Action 2"));
action->setCheckable(true);
action = submenu->addAction(tr("Action 3"));
action->setCheckable(true);
action->setChecked(true);
submenu->addSeparator();
submenu->addAction(style()->standardIcon(QStyle::SP_DriveFDIcon), tr("Action 4"));
submenu->addAction(style()->standardIcon(QStyle::SP_DriveHDIcon), tr("Action 5"));

return menu;
}

} // namespace Plugin
3 changes: 2 additions & 1 deletion src/plugins/guiplugin/guiwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class GuiWidget : public QWidget
private:
void setupUI();
auto createButtonGroup() -> QGroupBox *;
auto createBoxGroup() -> QGroupBox *;
auto createInputGroup() -> QGroupBox *;
auto createBarGroup() -> QGroupBox *;
auto createMenu() -> QMenu *;
};

} // namespace Plugin
Expand Down
Loading

0 comments on commit abb0604

Please sign in to comment.