Skip to content

Commit 01d5c57

Browse files
authored
Merge pull request #77 from cyc1ingsir/feature/control-panel-ui-redesign
Redesign of control panel's UI
2 parents 968ca27 + b8b53f8 commit 01d5c57

File tree

8 files changed

+663
-123
lines changed

8 files changed

+663
-123
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-added macros plugin to support similar to br@y's terminal
55
-added netproxy plugin
66
-improved logfile handling
7+
-redesign control panel's opening button
78

89
0.45.0, June 17 , 2018
910
-Enable input of Crl characters using a popup or Ctrl+<x>

controlpanel.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QLineEdit>
2727
#include <QPropertyAnimation>
2828
#include <QSerialPortInfo>
29+
#include <QShortcut>
2930
#include <QtWidgets/QComboBox>
3031

3132
#include "qdebug.h"
@@ -37,6 +38,9 @@ ControlPanel::ControlPanel(QWidget *parent, Settings *settings)
3738
{
3839
this->setupUi(this);
3940

41+
showIcon = m_panel_settings->tabIcon(0);
42+
hideIcon.addFile(QStringLiteral(":/images/hide.svg"));
43+
4044
m_baudValidator = new QIntValidator(0, 9999999, this);
4145
m_combo_Baud->setInsertPolicy(QComboBox::NoInsert);
4246
const Settings::Session session = settings->getCurrentSession();
@@ -69,22 +73,38 @@ ControlPanel::ControlPanel(QWidget *parent, Settings *settings)
6973
m_dtr_line->setEnabled(false);
7074

7175
// Connect button signal to slot
72-
connect(m_bt_settings, &QPushButton::clicked, this, &ControlPanel::toggleMenu);
76+
connect(m_panel_settings, &QTabWidget::tabBarClicked, this, &ControlPanel::tabClicked);
7377
connect(m_bt_open, &QPushButton::clicked, this, &ControlPanel::toggleDevice);
7478
connect(m_combo_Baud, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
7579
&ControlPanel::customBaudRate);
7680
}
7781

7882
/**
83+
* Overriden from QWidget
84+
* @brief ControlPanel::resize
85+
* @param w
86+
* @param h
87+
*/
88+
void ControlPanel::resize(int w, int h)
89+
{
90+
QWidget::resize(w, h);
91+
m_panel_settings->resize(w - m_x, m_panel_settings->height());
92+
}
93+
94+
/**
95+
* This method "hides" the control panel when called.
96+
* It needs to be called once initially right after the programs start.
7997
*
8098
* @brief ControlPanel::collapse
8199
*/
82100
void ControlPanel::collapse()
83101
{
84-
QPoint btnPosition = m_bt_settings->mapToParent(m_bt_settings->rect().topLeft());
102+
QPoint cornerPosition = m_device_control_bar->mapToParent(m_device_control_bar->rect().topLeft());
85103

86-
m_y = -(btnPosition.y() + 5);
87-
// qDebug() << Q_FUNC_INFO << m_y << " : " << m_x;
104+
// the 4 additional pixel will make the tab widget's lower edge visible
105+
// indicating that the settings "button" will reveal more when clicked
106+
m_y = -(cornerPosition.y() - 4);
107+
// qDebug() << Q_FUNC_INFO << m_x << " : " << m_y;
88108
move(m_x, m_y);
89109
m_menuVisible = false;
90110
}
@@ -101,29 +121,20 @@ void ControlPanel::slideOut()
101121

102122
ControlPanel::~ControlPanel() {}
103123

104-
// for debugging
105-
void ControlPanel::printPosition()
106-
{
107-
qDebug() << "toParent pos" << m_bt_settings->mapToParent(m_bt_settings->pos());
108-
qDebug() << "toParten topRight" << m_bt_settings->mapToParent(m_bt_settings->rect().topLeft());
109-
}
110-
111124
void ControlPanel::toggleMenu()
112125
{
113126
// Create animation
114127
QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
115-
// bool m_menuVisible = (y() < -3);
116-
QPoint endPos = m_menuVisible ? QPoint(m_x, m_y) : QPoint(m_x, -3);
128+
QPoint endPos = m_menuVisible ? QPoint(m_x, m_y) : QPoint(m_x, -13);
117129
// qDebug() << m_menuVisible << endPos;
118130
animation->setStartValue(pos());
119131
animation->setEndValue(endPos);
120132
animation->start();
121133
if (m_menuVisible) {
122-
m_bt_settings->setText("&Settings");
134+
m_panel_settings->setTabIcon(0, showIcon);
123135
m_menuVisible = false;
124136
} else {
125-
m_bt_settings->setText("^");
126-
m_bt_settings->setShortcut(Qt::KeyboardModifier::AltModifier + Qt::Key_S);
137+
m_panel_settings->setTabIcon(0, hideIcon);
127138
m_menuVisible = true;
128139
m_combo_Baud->setFocus();
129140
}
@@ -139,15 +150,15 @@ void ControlPanel::toggleDevice(bool open)
139150
m_rts_line->setEnabled(true);
140151
m_dtr_line->setEnabled(true);
141152

142-
m_bt_settings->setEnabled(false);
153+
m_panel_settings->setEnabled(false);
143154
m_bt_open->setText(tr("Cl&ose"));
144155
emit openDeviceClicked();
145156
} else {
146157
// Disable RTS and DTR checkboxes when closing device.
147158
m_rts_line->setEnabled(false);
148159
m_dtr_line->setEnabled(false);
149160

150-
m_bt_settings->setEnabled(true);
161+
m_panel_settings->setEnabled(true);
151162
emit closeDeviceClicked();
152163
m_bt_open->setText(tr("&Open"));
153164
}

controlpanel.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class ControlPanel : public QFrame, public Ui::ControlPanel
3232
{
3333
Q_OBJECT
3434

35+
friend class MainWindow;
36+
3537
signals:
3638
void openDeviceClicked();
3739
void closeDeviceClicked();
@@ -47,8 +49,8 @@ class ControlPanel : public QFrame, public Ui::ControlPanel
4749
* @return
4850
*/
4951
int hiddenHeight() { return height() + m_y; }
50-
void printPosition();
5152
void collapse();
53+
void resize(int w, int h);
5254
void slideOut();
5355
/**
5456
* @brief setLeftMargin
@@ -74,6 +76,11 @@ class ControlPanel : public QFrame, public Ui::ControlPanel
7476
void fillOpenModeCombo();
7577

7678
// slots
79+
void tabClicked(int i)
80+
{
81+
Q_UNUSED(i);
82+
toggleMenu();
83+
}
7784
void toggleMenu();
7885
void toggleDevice(bool open);
7986
void customBaudRate(int index);
@@ -95,6 +102,8 @@ class ControlPanel : public QFrame, public Ui::ControlPanel
95102
bool m_menuVisible;
96103
QIntValidator *m_baudValidator;
97104
QLineEdit *m_baud_edit;
105+
QIcon showIcon;
106+
QIcon hideIcon;
98107
};
99108

100109
#endif // CONTROLPANEL_H

0 commit comments

Comments
 (0)