From 5f8e33d2e35e83acf7de3fea6ad415cef034031b Mon Sep 17 00:00:00 2001 From: Krad Date: Tue, 7 Jun 2022 15:08:00 +0800 Subject: [PATCH] Rename Listbox to ListBox, and refactor. --- src/EditPatientDialog.cpp | 6 +++--- src/components/ListBox.cpp | 27 +++++++++++++++++++++++++++ src/components/ListBox.h | 22 ++++++++++++++++++++++ src/components/Listbox.cpp | 20 -------------------- src/components/Listbox.h | 21 --------------------- 5 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 src/components/ListBox.cpp create mode 100644 src/components/ListBox.h delete mode 100644 src/components/Listbox.cpp delete mode 100644 src/components/Listbox.h diff --git a/src/EditPatientDialog.cpp b/src/EditPatientDialog.cpp index 39ba09e..6c8f897 100644 --- a/src/EditPatientDialog.cpp +++ b/src/EditPatientDialog.cpp @@ -12,7 +12,7 @@ #include "EditPatientDialog.h" #include "dialogs/SelectDialog.h" #include "DateSelectDialog.h" -#include "components/Listbox.h" +#include "components/ListBox.h" int queryValue(QSqlTableModel* model, int colID, const QVariant& var) { @@ -54,7 +54,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo QLabel* lbl_sex= new QLabel(this); lbl_sex->setText(tr("Gender")); layout->addWidget(lbl_sex); - btnSex = new Listbox(this); + btnSex = new ListBox(this); btnSex->setText(tr("Female")); btnSex->setProperty("idx",0); btnSex->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -87,7 +87,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo lbl_date->setText(tr("Birth Date")); layout->addWidget(lbl_date); - btnDate = new Listbox(this); + btnDate = new ListBox(this); btnDate->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); btnDate->setLayoutDirection(Qt::RightToLeft); btnDate->setObjectName("editvalBtn"); diff --git a/src/components/ListBox.cpp b/src/components/ListBox.cpp new file mode 100644 index 0000000..054c48a --- /dev/null +++ b/src/components/ListBox.cpp @@ -0,0 +1,27 @@ +// +// Created by Krad on 2022/3/21. +// +#include "ListBox.h" + +#include +#include +#include + +ListBox::ListBox(QWidget *parent) : QToolButton(parent) { + +} + +void ListBox::paintEvent(QPaintEvent *e) { + QString temp = this->text(); + this->setText(""); + QToolButton::paintEvent(e); + this->setText(temp); + QStylePainter painter(this); + QStyleOptionToolButton opt; + initStyleOption(&opt); + int x = (size().width() - this->iconSize().width()) / 2 - (this->text().length() * opt.font.pixelSize()) / 4; + int y = this->iconSize().height() + 2; + painter.drawText(x,y,this->text()); +} + + diff --git a/src/components/ListBox.h b/src/components/ListBox.h new file mode 100644 index 0000000..2ab45ad --- /dev/null +++ b/src/components/ListBox.h @@ -0,0 +1,22 @@ +// +// Created by Krad on 2022/3/21. +// + +#ifndef GUI_LISTBOX_H +#define GUI_LISTBOX_H + +#include + +class ListBox: public QToolButton { +public: + explicit ListBox(QWidget* parent = nullptr); + ~ListBox() override = default; + +protected: + void paintEvent(QPaintEvent* e) override; + +private: +}; + + +#endif //GUI_LISTBOX_H diff --git a/src/components/Listbox.cpp b/src/components/Listbox.cpp deleted file mode 100644 index ed2c5f8..0000000 --- a/src/components/Listbox.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by Krad on 2022/3/21. -// - -#include -#include -#include -#include "Listbox.h" - -void Listbox::paintEvent(QPaintEvent *e) { - QString temp = this->text(); - this->setText(""); - QToolButton::paintEvent(e); - this->setText(temp); - QStylePainter p(this); - QStyleOptionToolButton opt; - initStyleOption(&opt); - - p.drawText((size().width()-this->iconSize().width())/2-(this->text().length()*opt.font.pixelSize())/4,this->iconSize().height()+2,this->text()); -} diff --git a/src/components/Listbox.h b/src/components/Listbox.h deleted file mode 100644 index 000a37f..0000000 --- a/src/components/Listbox.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by Krad on 2022/3/21. -// - -#ifndef GUI_LISTBOX_H -#define GUI_LISTBOX_H - -#include -class Listbox: public QToolButton { -public: - explicit Listbox(QWidget* parent = nullptr){}; - virtual ~Listbox(){}; - -protected: - virtual void paintEvent(QPaintEvent* e) override; - -private: -}; - - -#endif //GUI_LISTBOX_H