diff --git a/Acrylic_Dialog.pro b/Acrylic_Dialog.pro index f4136f2..bac29cf 100644 --- a/Acrylic_Dialog.pro +++ b/Acrylic_Dialog.pro @@ -46,7 +46,15 @@ HEADERS += \ FORMS += \ acrylic.ui +RC_ICONS = favicon.ico + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +DISTFILES += + +RESOURCES += \ + htmlInfo.qrc \ + icon.qrc diff --git a/Acrylic_Dialog.pro.user b/Acrylic_Dialog.pro.user index 61a5d14..1006d29 100644 --- a/Acrylic_Dialog.pro.user +++ b/Acrylic_Dialog.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -94,7 +94,7 @@ Desktop Qt 6.1.2 MSVC2019 64bit Desktop Qt 6.1.2 MSVC2019 64bit qt.qt6.612.win64_msvc2019_64_kit - 0 + 1 0 0 @@ -294,12 +294,14 @@ 2 - ProjectExplorer.CustomExecutableRunConfiguration - + Qt4ProjectManager.Qt4RunConfiguration:E:/Documents/Coding Repositories/Qt Default Repository/Acrylic_Dialog/Acrylic_Dialog.pro + E:/Documents/Coding Repositories/Qt Default Repository/Acrylic_Dialog/Acrylic_Dialog.pro false true + true false true + E:/Documents/Coding Repositories/Qt Default Repository/build-Acrylic_Dialog-Desktop_Qt_6_1_2_MSVC2019_64bit-Release 1 diff --git a/acrylic.cpp b/acrylic.cpp index f483899..0c854ad 100644 --- a/acrylic.cpp +++ b/acrylic.cpp @@ -17,6 +17,7 @@ Acrylic::Acrylic(QWidget *parent) ui->setupUi(this); ui->verticalLayout->setAlignment(Qt::AlignTop); this->resize(_width, _height); + this->setWindowIcon(QIcon(":/icon/icon")); /****************************************************************************/ /********************Things to do with the Acrylic Window********************/ @@ -135,6 +136,30 @@ Acrylic::Acrylic(QWidget *parent) ui->opClear ->setClickedColor(QColor(30, 30, 30, 70)); ui->bckSpace->setClickedColor(QColor(30, 30, 30, 70)); + //setButtonFont + ui->opAdd ->_setFont(QFont("Arita Sans Thin", 22)); + ui->opSub ->_setFont(QFont("Arita Sans Thin", 22)); + ui->opMulti ->_setFont(QFont("Arita Sans Thin", 19)); + ui->opDiv ->_setFont(QFont("Arita Sans Thin", 12)); + ui->opSqr ->_setFont(QFont("Microsoft YaHei Light", 12)); + ui->opPow ->_setFont(QFont("Microsoft YaHei Light", 12)); + ui->opMod ->_setFont(QFont("Microsoft YaHei Light", 12)); + ui->opBrckL ->_setFont(QFont("Arita Sans Thin", 12)); + ui->opBrckR ->_setFont(QFont("Arita Sans Thin", 12)); + ui->opClear ->_setFont(QFont("Microsoft YaHei Light", 12)); + ui->bckSpace->_setFont(QFont("Arita Sans Thin", 11)); + + ui->num0->_setFont(QFont("Microsoft YaHei", 13)); + ui->num1->_setFont(QFont("Microsoft YaHei", 13)); + ui->num2->_setFont(QFont("Microsoft YaHei", 13)); + ui->num3->_setFont(QFont("Microsoft YaHei", 13)); + ui->num4->_setFont(QFont("Microsoft YaHei", 13)); + ui->num5->_setFont(QFont("Microsoft YaHei", 13)); + ui->num6->_setFont(QFont("Microsoft YaHei", 13)); + ui->num7->_setFont(QFont("Microsoft YaHei", 13)); + ui->num8->_setFont(QFont("Microsoft YaHei", 13)); + ui->num9->_setFont(QFont("Microsoft YaHei", 13)); + //Connect the buttons with input connect(ui->num0, &QPushButton::clicked, [=](){expr.insert('0'); RfrInput(); UpdStack();}); connect(ui->num1, &QPushButton::clicked, [=](){expr.insert('1'); RfrInput(); UpdStack();}); @@ -315,3 +340,118 @@ void Acrylic::windowMaximum(){ isMaximum = false; } } + +void Acrylic::keyPressEvent(QKeyEvent *event){ + switch(event->key()){ + case Qt::Key_0: + expr.insert('0'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_1: + expr.insert('1'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_2: + expr.insert('2'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_3: + expr.insert('3'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_4: + expr.insert('4'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_5: + expr.insert('5'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_6: + expr.insert('6'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_7: + expr.insert('7'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_8: + expr.insert('8'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_9: + expr.insert('9'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_ParenLeft: + expr.insert('('); + RfrInput(); + UpdStack(); + break; + case Qt::Key_ParenRight: + expr.insert(')'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_Backspace: + expr.backSpace(); + RfrInput(); + UpdStack(true); + break; + case Qt::Key_Plus: + expr.insert('+'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_Minus: + expr.insert('-'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_Asterisk: + expr.insert('*'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_Slash: + expr.insert('/'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_Percent: + expr.insert('%'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_AsciiCircum: + expr.insert('^'); + RfrInput(); + UpdStack(); + break; + case Qt::Key_C: + expr.clr(); + RfrInput(); + UpdStack(true); + break; + case Qt::Key_Equal: + case Qt::Key_Enter: + expr.insert('#'); + UpdStack(); + RfrInput(); + RfrResult(); + UpdHistory(); + default: + //expr.insert(event->text().at(0).toLatin1()); + break; + } +} diff --git a/acrylic.h b/acrylic.h index 7b2f288..32b13bc 100644 --- a/acrylic.h +++ b/acrylic.h @@ -2,6 +2,7 @@ #define ACRYLIC_H #include +#include #include "WindowCompositionAttribute.h" #include "additiontabwidget.h" #include "ConvertFunc.h" @@ -17,11 +18,15 @@ class Acrylic : public QDialog public: Acrylic(QWidget *parent = nullptr); ~Acrylic(); + +private: void paintEvent(QPaintEvent *event); void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void leaveEvent(QEvent *event){this->setCursor(Qt::ArrowCursor); pressed = false; mouseState = 0;} + void keyPressEvent(QKeyEvent* event); + //void keyReleaseEvent(QKeyEvent* event); private: diff --git a/acrylic.ui b/acrylic.ui index 8092119..755da57 100644 --- a/acrylic.ui +++ b/acrylic.ui @@ -6,7 +6,7 @@ 0 0 - 549 + 473 511 @@ -116,6 +116,9 @@ 16777215 + + Qt::NoFocus + - @@ -144,6 +147,9 @@ 16777215 + + Qt::NoFocus + @@ -178,6 +184,9 @@ true + + Qt::NoFocus + false @@ -390,7 +399,7 @@ 等线 - 30 + 32 75 true PreferAntialias @@ -464,6 +473,9 @@ 45 + + Qt::TabFocus + 1 @@ -483,6 +495,9 @@ 45 + + Qt::TabFocus + . @@ -502,6 +517,9 @@ 45 + + Qt::TabFocus + / @@ -521,6 +539,9 @@ 45 + + Qt::TabFocus + 7 @@ -540,6 +561,9 @@ 45 + + Qt::TabFocus + 3 @@ -559,6 +583,9 @@ 45 + + Qt::TabFocus + ^ @@ -578,6 +605,9 @@ 45 + + Qt::TabFocus + 0 @@ -600,6 +630,9 @@ = + + true + @@ -616,8 +649,11 @@ 45 + + Qt::TabFocus + - * + × @@ -635,6 +671,9 @@ 45 + + Qt::TabFocus + 8 @@ -654,6 +693,9 @@ 45 + + Qt::TabFocus + 6 @@ -673,6 +715,9 @@ 45 + + Qt::TabFocus + 5 @@ -692,6 +737,9 @@ 45 + + Qt::TabFocus + 2 @@ -711,9 +759,15 @@ 45 + + Qt::TabFocus + + + + false + @@ -730,6 +784,9 @@ 45 + + Qt::TabFocus + - @@ -749,6 +806,9 @@ 45 + + Qt::TabFocus + 4 @@ -768,6 +828,9 @@ 45 + + Qt::TabFocus + 9 @@ -787,8 +850,11 @@ 45 + + Qt::TabFocus + - C + c @@ -806,8 +872,11 @@ 45 + + Qt::TabFocus + - Sqr + @@ -831,6 +900,9 @@ 16777215 + + Qt::TabFocus + ( @@ -850,6 +922,9 @@ 45 + + Qt::TabFocus + ) @@ -869,8 +944,11 @@ 45 + + Qt::TabFocus + - BackSpace + <- @@ -888,6 +966,9 @@ 45 + + Qt::TabFocus + % diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..e2bdd22 Binary files /dev/null and b/favicon.ico differ diff --git a/htmlInfo.qrc b/htmlInfo.qrc new file mode 100644 index 0000000..e05dcfa --- /dev/null +++ b/htmlInfo.qrc @@ -0,0 +1,5 @@ + + + info.html + + diff --git a/icon.qrc b/icon.qrc new file mode 100644 index 0000000..4ec2d99 --- /dev/null +++ b/icon.qrc @@ -0,0 +1,5 @@ + + + favicon.ico + + diff --git a/info.html b/info.html new file mode 100644 index 0000000..5c50e97 --- /dev/null +++ b/info.html @@ -0,0 +1,57 @@ +

+ About This Application: +

+

+ Author :  +

+

+ Jonathan Zhang ( Linloir ) +

+

+ Version :  +

+

+ 2.0 +

+

+ Info :  +

+

+ This is a open-source project based on GNU License. +

+

+ The Aero / Acrylic effect is based on Windows's API +

+

+ Everything else is done independently, including the tab page controller and the scroll area effect. +

+

+ All the animation effects are designed independently too. +

+

+
+

+

+ GitHub :  +

+

+ https://github.com/Linloir/Acrylic_Expression_Calculator_in_Qt.git +

+

+
+

+

+ Gitee :  +

+

+ https://gitee.com/linloir/Acrylic_Expression_Calculator_in_Qt.git +

+

+
+

+

+ CSDN :  +

+

+ Linloir - Windows+Qt 简单表达式计算器实现 +

\ No newline at end of file diff --git a/infopage.cpp b/infopage.cpp index a0fb575..7411105 100644 --- a/infopage.cpp +++ b/infopage.cpp @@ -5,9 +5,20 @@ InfoPage::InfoPage(QWidget* parent) : TabPage(parent) QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->setContentsMargins(0, 0, 0, 0); this->setLayout(mainLayout); - mainLayout->setAlignment(Qt::AlignCenter); - QTextBrowser* InfoBrowser = new QTextBrowser(this); - InfoBrowser->setHtml("

\ + //mainLayout->setAlignment(Qt::AlignCenter); + + QFile htmlPage(":/html/info.html"); + QString html; + if (htmlPage.open(QIODevice::ReadOnly | QIODevice::Text)){ + while (!htmlPage.atEnd()){ + QByteArray line = htmlPage.readLine(); + QString str(line); + html.append(str); + } + htmlPage.close(); + } + else{ + html.append("

\ About This Application:\

\

\ @@ -22,7 +33,16 @@ InfoPage::InfoPage(QWidget* parent) : TabPage(parent)

\
\

"); + } + + QTextBrowser* InfoBrowser = new QTextBrowser; + InfoBrowser->setHtml(html); InfoBrowser->setStyleSheet("background:transparent;border-width:0;border-style:outset"); InfoBrowser->setOpenExternalLinks(true); - mainLayout->addWidget(InfoBrowser); + InfoBrowser->resize(InfoBrowser->width(), 800); + //InfoBrowser->setAttribute(Qt::WA_TransparentForMouseEvents); + + ScrollAreaCustom* scrollarea = new ScrollAreaCustom(this); + mainLayout->addWidget(scrollarea); + scrollarea->addWidget(InfoBrowser); } diff --git a/infopage.h b/infopage.h index e94b1b8..b3c049b 100644 --- a/infopage.h +++ b/infopage.h @@ -2,10 +2,14 @@ #define INFOPAGE_H #include "tabpage.h" +#include "scrollareacustom.h" #include #include #include #include +#include +#include +#include class InfoPage : public TabPage { diff --git a/main.cpp b/main.cpp index a7542aa..42e5a68 100644 --- a/main.cpp +++ b/main.cpp @@ -6,10 +6,12 @@ HashMap opMap; int main(int argc, char *argv[]) { + //QApplication::setQuitOnLastWindowClosed(true); QApplication a(argc, argv); - Acrylic w; - w.setWindowFlags(Qt::FramelessWindowHint); - w.setAttribute(Qt::WA_TranslucentBackground); - w.show(); + Acrylic* w = new Acrylic; + w->setWindowFlags(Qt::FramelessWindowHint); + w->setAttribute(Qt::WA_TranslucentBackground); + w->setAttribute(Qt::WA_DeleteOnClose); + w->show(); return a.exec(); } diff --git a/qtransparentbutton.cpp b/qtransparentbutton.cpp index ef240f3..4315255 100644 --- a/qtransparentbutton.cpp +++ b/qtransparentbutton.cpp @@ -19,7 +19,10 @@ void QTransparentButton::paintEvent(QPaintEvent *event){ //test.setBrush(Qt::NoBrush); QPainter textPainter(this); - QFont textFont("FuturaNo2D", 14); + textPainter.setRenderHint(QPainter::TextAntialiasing); + textPainter.setPen(textColor); + textFont.setBold(bold); + //QFont textFont("FuturaNo2D", 14); textPainter.setFont(textFont); int widthOfText = textPainter.fontMetrics().size(Qt::TextSingleLine, buttonText).width(); int heightOfText = textPainter.fontMetrics().ascent() - textPainter.fontMetrics().descent() + textPainter.fontMetrics().leading(); diff --git a/qtransparentbutton.h b/qtransparentbutton.h index c66cc54..14dd573 100644 --- a/qtransparentbutton.h +++ b/qtransparentbutton.h @@ -25,11 +25,18 @@ class QTransparentButton : public QPushButton QColor bgColor_Hover = QColor(190, 190, 190, 70); QColor bgColor_Clicked = QColor(170, 170, 170, 70); + QFont textFont = QFont("Microsoft YaHei Light", 14); + QColor textColor = QColor(0, 0, 0, 255); + bool bold = false; + public: QTransparentButton(QWidget* parent = nullptr); void setColor(QColor c); void setClickedColor(QColor c); void setHoverColor(QColor c); + void _setFont(const QFont &f){textFont = f;} + void _setTextColor(QColor c){textColor = c;} + void _setTextBold(bool b){bold = b;} }; #endif // QTRANSPARENTBUTTON_H diff --git a/stackpage.cpp b/stackpage.cpp index 1ec55cc..a433a2f 100644 --- a/stackpage.cpp +++ b/stackpage.cpp @@ -4,10 +4,12 @@ StackPage::StackPage(QWidget* parent) : TabPage(parent) { this->setMouseTracking(true); //this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QVBoxLayout* mainLayout = new QVBoxLayout; + QHBoxLayout* mainLayout = new QHBoxLayout; mainLayout->setContentsMargins(0, 0, 0, 0); this->setLayout(mainLayout); + QVBoxLayout* numLayout = new QVBoxLayout; + numLayout->setContentsMargins(0, 0, 0, 0); QLabel* labNum = new QLabel; QFont labFont("DengXian", 13); labFont.setBold(true); @@ -16,22 +18,27 @@ StackPage::StackPage(QWidget* parent) : TabPage(parent) labNum->setAlignment(Qt::AlignRight | Qt::AlignTop); labNum->setStyleSheet("color:#E75E5E5E;"); labNum->setMaximumHeight(20); - mainLayout->addWidget(labNum); + numLayout->addWidget(labNum); numStackScrollArea = new ScrollAreaCustom(this); - mainLayout->addWidget(numStackScrollArea); + numLayout->addWidget(numStackScrollArea); + QVBoxLayout* opLayout = new QVBoxLayout; + opLayout->setContentsMargins(0, 0, 0, 0); QLabel* labOp = new QLabel; labFont.setBold(true); - labOp->setText("Operator Stack"); + labOp->setText("Op Stack"); labOp->setFont(labFont); labOp->setAlignment(Qt::AlignRight | Qt::AlignTop); labOp->setStyleSheet("color:#E75E5E5E;"); labOp->setMaximumHeight(20); - mainLayout->addWidget(labOp); + opLayout->addWidget(labOp); opStackScrollArea = new ScrollAreaCustom(this); - mainLayout->addWidget(opStackScrollArea); + opLayout->addWidget(opStackScrollArea); + + mainLayout->addLayout(opLayout); + mainLayout->addLayout(numLayout); //qDebug() << "StackPageWidth:[" << this->x() << "," << this->y() << "," << this->width() << "," << this->height() << "]\n"; } @@ -66,6 +73,7 @@ void StackPage::RfrStack(const QString & numDif, const QString & opDif){ } } QString opDifCpy = opDif; + opDifCpy.replace('*', "×").replace('/', "÷"); if(!opDif.isEmpty()){ QTextStream opStream(&opDifCpy); if(opDif[0] == 'r'){ @@ -90,7 +98,7 @@ void StackPage::RfrStack(const QString & numDif, const QString & opDif){ newChar->setFont(font); newChar->setAlignment(Qt::AlignRight); newChar->resize(newChar->width(), 30); - newChar->setText(QString::asprintf("%c", c)); + newChar->setText(QString::asprintf("%c%s", c, c == '(' ? " " : "")); opStackScrollArea->addWidget(newChar); } }