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 */
82100void 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
102122ControlPanel::~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-
111124void 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 }
0 commit comments