Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复了计算器UI 按钮间隔不一致的问题 #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/control/basickeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

#include "dthememanager.h"

const int KEYPAD_HEIGHT = 316; //键盘界面高度
const int KEYPAD_SPACING = 3; //键盘按键间距,按钮比ui大2pix,此处小2pix
const QSize STANDARD_TEXTBTNSIZE = QSize(79, 58); //标准模式按钮大小,为画边框比ui大2pix
const int STANDARD_WIDTH = 352; //标准模式宽度
const int KEYPAD_SPACING = 4; //键盘按键间距
const int KEYPAD_HEIGHT = STANDARD_TEXTBTNSIZE.height() * 5 + KEYPAD_SPACING * 4; //键盘界面高度, 306
const int KEYPAD_WIDTH = STANDARD_TEXTBTNSIZE.width() * 4 + KEYPAD_SPACING * 3; //键盘界面宽度, 328
const int LEFT_MARGIN = 12; //键盘左边距
const int RIGHT_MARGIN = 13; //键盘右边距
const int BOTTOM_MARGIN = 11; //键盘下边距
const QSize STANDARD_TEXTBTNSIZE = QSize(78, 58); //标准模式按钮大小,为画边框比ui大2pix
//const int RIGHT_MARGIN = 12; //键盘右边距
//const int BOTTOM_MARGIN = 11; //键盘下边距

const BasicKeypad::KeyDescription BasicKeypad::keyDescriptions[] = {
// {"MC", Key_MC, 1, 0, 1, 2}, {"MR", Key_MR, 1, 2, 1, 2},
Expand Down Expand Up @@ -68,12 +70,14 @@ const BasicKeypad::KeyDescription BasicKeypad::keyDescriptions[] = {

BasicKeypad::BasicKeypad(QWidget *parent)
: DWidget(parent),
m_layout(new QGridLayout(this)),
//m_layout(new QGridLayout(this)),
m_mapper(new QSignalMapper(this))
{
this->setFixedHeight(KEYPAD_HEIGHT);
QWidget* grid_container = new QWidget(this);
grid_container->setGeometry(LEFT_MARGIN, 0, KEYPAD_WIDTH, KEYPAD_HEIGHT);
grid_container->setFixedSize(KEYPAD_WIDTH, KEYPAD_HEIGHT);
m_layout = new QGridLayout(grid_container);
m_layout->setMargin(0);
m_layout->setSpacing(KEYPAD_SPACING);
m_layout->setContentsMargins(0, 0, 0, 0);
// setFocusPolicy(Qt::StrongFocus);

Expand Down Expand Up @@ -172,9 +176,8 @@ void BasicKeypad::initButtons()
}
}

button->setFixedSize(STANDARD_TEXTBTNSIZE);
m_layout->addWidget(button, desc->row, desc->column, desc->rowcount, desc->columncount,
Qt::AlignHCenter | Qt::AlignVCenter);
button->setMaximumSize(STANDARD_TEXTBTNSIZE);
m_layout->addWidget(button, desc->row, desc->column, desc->rowcount, desc->columncount);
const QPair<DPushButton *, const KeyDescription *> hashValue(button, desc);
m_keys.insert(desc->button, hashValue); //key为枚举值,value.first为DPushButton *, value.second为const KeyDescription *

Expand All @@ -197,7 +200,10 @@ void BasicKeypad::initUI()
button(Key_Min)->setObjectName("SymbolButton");
button(Key_Plus)->setObjectName("SymbolButton");

this->setContentsMargins(LEFT_MARGIN, 0, RIGHT_MARGIN, BOTTOM_MARGIN);
m_layout->setVerticalSpacing(KEYPAD_SPACING);
m_layout->setHorizontalSpacing(KEYPAD_SPACING);

//this->setContentsMargins(LEFT_MARGIN, 0, RIGHT_MARGIN, BOTTOM_MARGIN);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/control/memhiskeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MemHisKeypad::MemHisKeypad(QWidget *parent)
m_layout->setContentsMargins(0, 0, 0, 0);

initButtons();
this->setContentsMargins(12, 0, 13, 0);
this->setContentsMargins(12, 0, 12, 0);

connect(m_mapper, SIGNAL(mapped(int)), SIGNAL(buttonPressed(int)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/control/memorykeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "memorykeypad.h"

const QSize MEMORYBUTTON_SIZE = QSize(52, 32); //标准模式大小,为画边框比ui大2pix
const QSize MEMORYBUTTON_SIZE = QSize(53, 32); //标准模式大小,为画边框比ui大2pix

const MemoryKeypad::KeyDescription MemoryKeypad::keyDescriptions[] = {
{"MC", Key_MC, 1, 0, 1, 1}, {"MR", Key_MR, 1, 1, 1, 1},
Expand All @@ -24,7 +24,7 @@ MemoryKeypad::MemoryKeypad(QWidget *parent)
m_layout->setContentsMargins(0, 0, 0, 0);

initButtons();
this->setContentsMargins(12, 0, 13, 0);
this->setContentsMargins(12, 0, 12, 0);

connect(m_mapper, SIGNAL(mapped(int)), SIGNAL(buttonPressed(int)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/control/procheckbtnkeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ProCheckBtnKeypad::ProCheckBtnKeypad(QWidget *parent)
{
this->setFixedHeight(45);
m_layout->setMargin(0);
m_layout->setSpacing(2); //按钮比ui大2pix,此处比ui小2pix
m_layout->setSpacing(3); //按钮比ui大2pix,此处比ui小2pix
m_layout->setContentsMargins(0, 0, 0, 0);

initButtons();
this->setContentsMargins(10, 0, 10, 0);
this->setContentsMargins(12, 0, 12, 0);

connect(m_mapper, SIGNAL(mapped(int)), SIGNAL(buttonPressed(int)));
}
Expand Down
32 changes: 20 additions & 12 deletions src/control/programmerkeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include "programmerkeypad.h"

const int KEYPAD_HEIGHT = 279; //键盘界面高度
const int KEYPAD_SPACING = 3; //键盘按键间距,按钮比ui大2pix,此处小2pix
const int LEFT_MARGIN = 10; //键盘左边距,按钮比ui大2pix,此处小2pix
const int RIGHT_MARGIN = 10; //键盘右边距,按钮比ui大2pix,此处小2pix
const int BOTTOM_MARGIN = 10; //键盘下边距,按钮比ui大2pix,此处小2pix
const QSize STANDARD_TEXTBTNSIZE = QSize(69, 42); //程序员模式按钮大小,为画边框比ui大2pix
const int KEYPAD_HEIGHT = 267; //键盘界面高度
const int KEYPAD_WIDTH = 429; //键盘界面高度
const int KEYPAD_SPACING = 3; //键盘按键间距,按钮比ui大2pix,此处小2pix
const int LEFT_MARGIN = 12; //键盘左边距,按钮比ui大2pix,此处小2pix
//const int RIGHT_MARGIN = 12; //键盘右边距,按钮比ui大2pix,此处小2pix
//const int BOTTOM_MARGIN = 10; //键盘下边距,按钮比ui大2pix,此处小2pix

const ProgrammerKeypad::KeyDescription ProgrammerKeypad::keyDescriptions[] = {
{"AND", Key_AND, 0, 0}, {"A", Key_A, 0, 1}, {"<<", Key_moveL, 0, 2},
Expand All @@ -34,14 +35,18 @@ const ProgrammerKeypad::KeyDescription ProgrammerKeypad::keyDescriptions[] = {

ProgrammerKeypad::ProgrammerKeypad(QWidget *parent)
: DWidget(parent),
m_layout(new QGridLayout(this)),
//m_layout(new QGridLayout(this)),
m_mapper(new QSignalMapper(this)),
m_leftBracket(new DLabel(this)),
m_rightBracket(new DLabel(this))
{
this->setFixedHeight(KEYPAD_HEIGHT);
QWidget* grid_container = new QWidget(this);
grid_container->setGeometry(LEFT_MARGIN, 0, KEYPAD_WIDTH, KEYPAD_HEIGHT);
grid_container->setFixedSize(KEYPAD_WIDTH, KEYPAD_HEIGHT);
m_layout = new QGridLayout(grid_container);


m_layout->setMargin(0);
m_layout->setSpacing(KEYPAD_SPACING);
m_layout->setContentsMargins(0, 0, 0, 0);
// setFocusPolicy(Qt::StrongFocus);
m_leftBracket->setFixedSize(24, 14);
Expand Down Expand Up @@ -151,10 +156,10 @@ void ProgrammerKeypad::initButtons()
}

if (desc->text == "=")
button->setFixedSize(69, 43);
button->setMaximumSize(69, 43);
else
button->setFixedSize(STANDARD_TEXTBTNSIZE);
m_layout->addWidget(button, desc->row, desc->column, Qt::AlignHCenter | Qt::AlignVCenter);
button->setMaximumSize(STANDARD_TEXTBTNSIZE);
m_layout->addWidget(button, desc->row, desc->column);
const QPair<DPushButton *, const KeyDescription *> hashValue(button, desc);
m_keys.insert(desc->button, hashValue); //key为枚举值,value.first为DPushButton *, value.second为const KeyDescription *

Expand Down Expand Up @@ -365,5 +370,8 @@ void ProgrammerKeypad::initUI()
button(Key_Min)->setObjectName("SymbolButton");
button(Key_Plus)->setObjectName("SymbolButton");

this->setContentsMargins(LEFT_MARGIN, 0, RIGHT_MARGIN, BOTTOM_MARGIN);
m_layout->setVerticalSpacing(3);
m_layout->setHorizontalSpacing(3);

//this->setContentsMargins(LEFT_MARGIN, 0, RIGHT_MARGIN, BOTTOM_MARGIN);
}
4 changes: 2 additions & 2 deletions src/control/prosystemkeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <QDebug>
#include "../../3rdparty/core/settings.h"

const QSize SYSTEMKEYPADSIZE = QSize(451, 279);
const int LEFT_MARGIN = 10; //键盘左边距
const QSize SYSTEMKEYPADSIZE = QSize(453, 279);
const int LEFT_MARGIN = 12; //键盘左边距
const int BOTTOM_MARGIN = 14; //键盘下边距

ProSystemKeypad::ProSystemKeypad(QWidget *parent)
Expand Down
42 changes: 25 additions & 17 deletions src/control/scientifickeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@

#include "dthememanager.h"

const int KEYPADHEIGHT = 350; //整体键盘的高度
const QSize BUTTON_SIZE = QSize(69, 46); //科学模式的固定大小
const int SCIENTIFIC_WIDTH = 453; //科学模式宽度
const int KEYPAD_SPACING = 3; //键盘按键间距
const int KEYPAD_HEIGHT = BUTTON_SIZE.height() * 7 + KEYPAD_SPACING * 6; //键盘界面高度, 340
const int KEYPAD_WIDTH = BUTTON_SIZE.width() * 6 + KEYPAD_SPACING * 5; //键盘界面宽度, 429
const int LEFT_MARGIN = 12; //键盘左边距
//const int RIGHT_MARGIN = 12; //键盘右边距
//const int BOTTOM_MARGIN = 11; //键盘下边距

const ScientificKeyPad::KeyDescription ScientificKeyPad::keyDescriptions[] = {
{"", Key_deg, 2, 0, 1, 1}, {"2ⁿᵈ", Key_page, 2, 1, 1, 1}, {"π", Key_PI, 2, 2, 1, 1},
Expand Down Expand Up @@ -94,7 +100,7 @@ const ScientificKeyPad::KeyDescription1 ScientificKeyPad::keyDescriptions1[] = {

ScientificKeyPad::ScientificKeyPad(QWidget *parent)
: DWidget(parent)
, m_gridlayout1(new QGridLayout(this))
//, m_gridlayout1(new QGridLayout(this))
, m_mapper(new QSignalMapper(this))
, m_leftBracket(new DLabel(this))
, m_rightBracket(new DLabel(this))
Expand All @@ -109,16 +115,15 @@ ScientificKeyPad::ScientificKeyPad(QWidget *parent)
, m_logyxwidget(new QStackedWidget(this))
, m_exwidget(new QStackedWidget(this))
{
this->setFixedHeight(KEYPADHEIGHT);
m_leftBracket->setFixedSize(24, 14);
m_rightBracket->setFixedSize(24, 14);
QWidget* grid_container = new QWidget(this);
grid_container->setGeometry(LEFT_MARGIN, 0, KEYPAD_WIDTH, KEYPAD_HEIGHT);
grid_container->setFixedSize(KEYPAD_WIDTH, KEYPAD_HEIGHT);
m_gridlayout1 = new QGridLayout(grid_container);
m_gridlayout1->setMargin(0);
m_gridlayout1->setContentsMargins(0, 0, 0, 0);

initButtons();
initUI();
m_gridlayout1->setMargin(0);
m_gridlayout1->setSpacing(3); //按钮比ui大2pix,此处小2pix
m_gridlayout1->setContentsMargins(0, 0, 0, 0);
this->setLayout(m_gridlayout1);

connect(m_mapper, SIGNAL(mapped(int)), SIGNAL(buttonPressed(int)));
connect(this, &ScientificKeyPad::buttonPressed, this,
Expand Down Expand Up @@ -228,6 +233,8 @@ void ScientificKeyPad::initButtons()
}
}

button->setMinimumSize(BUTTON_SIZE);

//stackwidget中按钮初始化
if ((i / 6 > 0) && (i % 6 == 0 || i % 6 == 1) && i != 30 && i != 36) {
DPushButton *pagebutton;
Expand Down Expand Up @@ -274,14 +281,13 @@ void ScientificKeyPad::initButtons()
initStackWidget(m_exwidget, button, pagebutton, desc1);
}

pagebutton->setFixedSize(BUTTON_SIZE);
pagebutton->setMaximumSize(BUTTON_SIZE);
button->setMaximumSize(BUTTON_SIZE);
connect(static_cast<TextButton *>(pagebutton), &TextButton::focus, this, &ScientificKeyPad::getFocus); //获取上下左右键
} else {
m_gridlayout1->addWidget(button, desc->row, desc->column, desc->rowcount, desc->columncount,
Qt::AlignCenter/* | Qt::AlignTop*/);
m_gridlayout1->addWidget(button, desc->row, desc->column, desc->rowcount, desc->columncount);
}

button->setFixedSize(BUTTON_SIZE);
const QPair<DPushButton *, const KeyDescription *> hashValue(button, desc);
m_keys.insert(desc->button, hashValue); //key为枚举值,value.first为DPushButton *, value.second为const KeyDescription *

Expand Down Expand Up @@ -345,7 +351,10 @@ void ScientificKeyPad::initUI()
button(Key_Min)->setObjectName("SymbolButton");
button(Key_Plus)->setObjectName("SymbolButton");

this->setContentsMargins(12, 0, 12, 12);
m_gridlayout1->setHorizontalSpacing(KEYPAD_SPACING);
m_gridlayout1->setVerticalSpacing(KEYPAD_SPACING);

//this->setContentsMargins(12, 0, 12, 12);
}

/**
Expand All @@ -361,9 +370,8 @@ void ScientificKeyPad::initStackWidget(QStackedWidget *widget, DPushButton *butt
widget->addWidget(button);
widget->addWidget(pagebutton);
widget->setCurrentIndex(0);
widget->setFixedSize(BUTTON_SIZE.width(), BUTTON_SIZE.height() + 4); //预留4pix给阴影
m_gridlayout1->addWidget(widget, desc1->row, desc1->column, desc1->rowcount, desc1->columncount,
Qt::AlignCenter/* | Qt::AlignTop*/);
widget->setMinimumSize(BUTTON_SIZE.width(), BUTTON_SIZE.height() + 4); //预留4pix给阴影
m_gridlayout1->addWidget(widget, desc1->row, desc1->column, desc1->rowcount, desc1->columncount);
const QPair<DPushButton *, const KeyDescription1 *> hashValue1(pagebutton, desc1);
m_keys1.insert(desc1->button, hashValue1); //key为枚举值,value.first为DPushButton *, value.second为const KeyDescription1 *
connect(pagebutton, &DPushButton::clicked, m_mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

DGUI_USE_NAMESPACE

const QSize STANDARD_SIZE = QSize(344, 545); //标准模式的固定大小
const QSize SCIENTIFIC_MIN_SIZE = QSize(451, 542); //科学模式的最小size
const QSize PROGRAMM_SIZE = QSize(451, 574); //程序员模式固定大小
const QSize STANDARD_SIZE = QSize(352, 548); //标准模式的固定大小
const QSize SCIENTIFIC_MIN_SIZE = QSize(453, 542); //科学模式的最小size
const QSize PROGRAMM_SIZE = QSize(453, 574); //程序员模式固定大小

MainWindow::MainWindow(QWidget *parent)
: DMainWindow(parent)
Expand Down
4 changes: 2 additions & 2 deletions src/views/memorywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
const int STANDARD_MWIDGET_HEIGHT = 260; //标准模式memorywidget高度
const int SCIENTIFIC_MWIDGET_HEIGHT = 302; //科学模式memorywidget高度
const int PROGRAMMER_MWIDGET_HEIGHT = 230; //程序猿模式memorywidget高度
const int STANDARD_ITEM_WIDTH = 344; //标准模式宽度
const int PRO_SCI_ITEM_WIDTH = 451; //科学-程序猿模式最小宽度
const int STANDARD_ITEM_WIDTH = 352; //标准模式宽度
const int PRO_SCI_ITEM_WIDTH = 453; //科学-程序猿模式最小宽度
const int STANDARD_FORMAT_PREC = 15; //标准模式科学计数位数
const int SCIENTIFIC_FORMAT_PREC = 31; //科学模式科学计数位数
const int MAXSIZE = 500; //内存保存最大数
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/programmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ProgramModule::ProgramModule(QWidget *parent)
m_stackWidget->addWidget(m_proSystemKeypad);
m_stackWidget->addWidget(m_memorylistwidget);
m_stackWidget->setCurrentWidget(m_programmerKeypad);
m_stackWidget->setFixedSize(451, 279);
m_stackWidget->setFixedSize(453, 279);

initArrowRectangle();

Expand Down