Skip to content

Commit

Permalink
Resizable console window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Nov 30, 2015
1 parent 4db0808 commit f816b06
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 598 deletions.
Binary file added bin/grblControl
Binary file not shown.
Binary file added bin/grblControl.exe
Binary file not shown.
119 changes: 54 additions & 65 deletions frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ frmMain::frmMain(QWidget *parent) :
connect(ui->tblProgram->verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(onScroolBarAction(int)));
clearTable();

// Console window handling
connect(ui->grpConsole, SIGNAL(resized(QSize)), this, SLOT(onConsoleResized(QSize)));
connect(ui->scrollAreaWidgetContents, SIGNAL(sizeChanged(QSize)), this, SLOT(onPanelsSizeChanged(QSize)));

// Loading settings
m_settingsFileName = qApp->applicationDirPath() + "/settings.ini";
loadSettings();
Expand All @@ -148,24 +152,14 @@ frmMain::frmMain(QWidget *parent) :
button->setChecked(button->text().toDouble() == ui->txtJogStep->value());
}

// Console window handling
connect(ui->grpConsole, SIGNAL(mouseMoved(int,int)), this, SLOT(onConsoleMouseMove(int,int)));
connect(ui->grpConsole, SIGNAL(mousePressed()), this, SLOT(onConsoleMousePress()));
connect(ui->grpConsole, SIGNAL(mouseReleased()), this, SLOT(onConsoleMouseRelease()));
connect(ui->grpConsole, SIGNAL(resized(QSize)), this, SLOT(onConsoleResized(QSize)));

ui->txtConsole->setMinimumHeight(1);

ui->splitPanels->setCollapsible(1, false);
connect(ui->scrollAreaWidgetContents, SIGNAL(sizeChanged(QSize)), this, SLOT(onPanelsSizeChanged(QSize)));
connect(ui->splitPanels, SIGNAL(splitterMoved(int,int)), this, SLOT(onPanelsSplitterMoved(int,int)));

show(); // Visibility bug workaround
applySettings();
updateControlsState();

this->installEventFilter(this);
ui->tblProgram->installEventFilter(this);
ui->tblProgram->installEventFilter(this);
ui->splitPanels->handle(1)->installEventFilter(this);
ui->splitPanels->installEventFilter(this);

connect(&m_timerConnection, SIGNAL(timeout()), this, SLOT(onTimerConnection()));
connect(&m_timerStateQuery, SIGNAL(timeout()), this, SLOT(onTimerStateQuery()));
Expand Down Expand Up @@ -246,7 +240,7 @@ void frmMain::loadSettings()
m_settings.setPanelJog(set.value("panelJogVisible", true).toBool());

m_settings.setFontSize(set.value("fontSize", 8).toInt());
// ui->txtConsole->setMinimumHeight(set.value("consoleMinHeight", 100).toInt());
ui->grpConsole->setMinimumHeight(set.value("consoleMinHeight", 100).toInt());

ui->chkAutoScroll->setChecked(set.value("autoScroll", false).toBool());
ui->sliSpindleSpeed->setValue(set.value("spindleSpeed", 100).toInt() / 100);
Expand Down Expand Up @@ -374,7 +368,7 @@ void frmMain::saveSettings()
set.setValue("panelFeedVisible", m_settings.panelFeed());
set.setValue("panelJogVisible", m_settings.panelJog());
set.setValue("fontSize", m_settings.fontSize());
set.setValue("consoleMinHeight", ui->txtConsole->minimumHeight());
set.setValue("consoleMinHeight", ui->grpConsole->minimumHeight());

set.setValue("heightmapBorderX", ui->txtHeightMapBorderX->value());
set.setValue("heightmapBorderY", ui->txtHeightMapBorderY->value());
Expand Down Expand Up @@ -1200,12 +1194,6 @@ void frmMain::resizeEvent(QResizeEvent *re)
placeVisualizerButtons();
resizeCheckBoxes();
resizeTableHeightMapSections();

int a = ui->splitPanels->height() - m_storedPanelsHeight - 6;
ui->splitPanels->setSizes(QList<int>() << m_storedPanelsHeight + 3 << a);

// ui->scrollArea->setMinimumSize(ui->scrollAreaWidgetContents->sizeHint());
// qDebug() << "viewport sizeHint:" << ui->scrollArea->viewport()->sizeHint() << ;
}

void frmMain::resizeTableHeightMapSections()
Expand Down Expand Up @@ -1699,50 +1687,6 @@ void frmMain::onTableCurrentChanged(QModelIndex idx1, QModelIndex idx2)
}
}

void frmMain::onConsoleMouseMove(int dx, int dy)
{
qDebug() << "mouse move";
// ui->grpConsole->setMinimumHeight(qBound(1, m_pressedConsoleMinHeight - dy, 300));
// if (ui->txtConsole->minimumHeight() > 1 && !ui->txtConsole->isVisible()) ui->txtConsole->setVisible(true);
int a = m_pressedHeight - dy;

if (a < m_pressedHeight && !ui->scrollArea->verticalScrollBar()->isVisible()) return;
ui->splitPanels->setSizes(QList<int>() << ui->splitPanels->height() - a << a);
}

void frmMain::onConsoleMousePress()
{
qDebug() << "mouse press";
// m_pressedConsoleMinHeight = ui->grpConsole->height();
m_pressedHeight = ui->splitPanels->sizes().at(1);
ui->splitPanels->setSizes(QList<int>() << ui->splitPanels->height() - ui->grpConsole->height() << ui->grpConsole->height());
ui->txtConsole->setMinimumHeight(1);
}

void frmMain::onConsoleMouseRelease()
{
if (ui->scrollArea->verticalScrollBar()->isVisible()) ui->txtConsole->setMinimumHeight(ui->txtConsole->height());
}

void frmMain::onConsoleResized(QSize size)
{
int pureHeight = ui->grpConsole->layout()->spacing() + ui->grpConsole->layout()->margin() * 2 + ui->cboCommand->height() + 3;
bool visible = ui->grpConsole->contentsRect().height() > pureHeight;
// if (ui->txtConsole->isVisible() != visible) ui->txtConsole->setVisible(visible);
}

void frmMain::onPanelsSizeChanged(QSize size)
{
qDebug() << "panels resized" << size.height() << ui->splitPanels->height();
int a = ui->splitPanels->height() - size.height() - 6;
ui->splitPanels->setSizes(QList<int>() << size.height() + 3 << a);
m_storedPanelsHeight = size.height();
}

void frmMain::onPanelsSplitterMoved(int pos, int index)
{
}

void frmMain::onTableInsertLine()
{
if (ui->tblProgram->selectionModel()->selectedRows().count() == 0 || m_processingFile) return;
Expand Down Expand Up @@ -2481,10 +2425,55 @@ bool frmMain::eventFilter(QObject *obj, QEvent *event)
ui->chkAutoScroll->setChecked(false);
}
}
} else if (event->type() == QEvent::MouseButtonPress) {
if (obj == ui->splitPanels->handle(1)) {
// Store current console group box minimum & real heights
m_storedConsoleMinimumHeight = ui->grpConsole->minimumHeight();
m_storedConsoleHeight = ui->grpConsole->height();

// Update splited sizes
ui->splitPanels->setSizes(QList<int>() << ui->scrollArea->height() << ui->grpConsole->height());

// Set new console mimimum height
int pureHeight = ui->grpConsole->height() - ui->grpConsole->contentsRect().height()
+ ui->spacerConsole->geometry().height() + ui->grpConsole->layout()->margin() * 2
+ ui->cboCommand->height() + 2;
ui->grpConsole->setMinimumHeight(qMax(pureHeight, ui->splitPanels->height()
- ui->scrollAreaWidgetContents->sizeHint().height() - ui->splitPanels->handleWidth() - 4));
}
} else if (event->type() == QEvent::MouseButtonRelease) {
if (obj == ui->splitPanels->handle(1)) {
// Store new console minimum height if height was changed with split handle
if (ui->grpConsole->height() != m_storedConsoleHeight) {
ui->grpConsole->setMinimumHeight(ui->grpConsole->height());
} else {
ui->grpConsole->setMinimumHeight(m_storedConsoleMinimumHeight);
}
}
} else if (event->type() == QEvent::Resize) {
if (obj == ui->splitPanels) {
// Resize splited widgets
onPanelsSizeChanged(ui->scrollAreaWidgetContents->sizeHint());
}
}

return QMainWindow::eventFilter(obj, event);
}

void frmMain::onConsoleResized(QSize size)
{
int pureHeight = ui->spacerConsole->geometry().height() + ui->grpConsole->layout()->margin() * 2 + ui->cboCommand->height() + 2;
bool visible = ui->grpConsole->contentsRect().height() > pureHeight;
if (ui->txtConsole->isVisible() != visible) ui->txtConsole->setVisible(visible);
}

void frmMain::onPanelsSizeChanged(QSize size)
{
ui->splitPanels->setSizes(QList<int>() << size.height() + 4
<< ui->splitPanels->height() - size.height()
- 4 - ui->splitPanels->handleWidth());
}

bool frmMain::keyIsMovement(int key)
{
return key == Qt::Key_4 || key == Qt::Key_6 || key == Qt::Key_8 || key == Qt::Key_2 || key == Qt::Key_9 || key == Qt::Key_3;
Expand Down
11 changes: 4 additions & 7 deletions frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ private slots:
void onActRecentFileTriggered();
void onCboCommandReturnPressed();
void onTableCurrentChanged(QModelIndex idx1, QModelIndex idx2);
void onConsoleMouseMove(int dx, int dy);
void onConsoleMousePress();
void onConsoleMouseRelease();
void onConsoleResized(QSize size);
void onPanelsSizeChanged(QSize size);
void onPanelsSplitterMoved(int pos, int index);

void on_actFileExit_triggered();
void on_cmdFileOpen_clicked();
Expand Down Expand Up @@ -228,9 +224,10 @@ private slots:
QString m_storedParserStatus;
double m_storedOffsets[1][3];

int m_consoleMinHeight;
int m_pressedHeight;
int m_storedPanelsHeight;
// Console window
int m_storedConsoleMinimumHeight;
int m_storedConsoleHeight;
int m_consolePureHeight;

// Flags
bool m_settingZeroXY = false;
Expand Down
57 changes: 51 additions & 6 deletions frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ QSlider::handle:horizontal:hover {
}*/</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<layout class="QHBoxLayout" name="horizontalLayout_5" stretch="100,1">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="grpProgram">
<property name="title">
Expand Down Expand Up @@ -1540,11 +1552,19 @@ QToolButton:checked { /* all types of tool button */
</item>
<item>
<widget class="QSplitter" name="splitPanels">
<property name="styleSheet">
<string notr="true">QSplitter::handle {
background-image: url(&quot;:/images/handle_small.png&quot;);
}</string>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="handleWidth">
<number>0</number>
<number>10</number>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="ScrollArea" name="scrollArea">
<property name="sizePolicy">
Expand Down Expand Up @@ -1573,8 +1593,8 @@ QToolButton:checked { /* all types of tool button */
<rect>
<x>0</x>
<y>0</y>
<width>238</width>
<height>644</height>
<width>228</width>
<height>609</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -2540,7 +2560,10 @@ QDoubleSpinBox:focus {
<property name="title">
<string>Console</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
Expand All @@ -2555,6 +2578,12 @@ QDoubleSpinBox:focus {
</property>
<item>
<widget class="QPlainTextEdit" name="txtConsole">
<property name="minimumSize">
<size>
<width>0</width>
<height>1</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
Expand All @@ -2565,6 +2594,22 @@ QDoubleSpinBox:focus {
</property>
</widget>
</item>
<item>
<spacer name="spacerConsole">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7" stretch="1,0,0">
<item>
Expand Down Expand Up @@ -2636,7 +2681,7 @@ QDoubleSpinBox:focus {
<x>0</x>
<y>0</y>
<width>870</width>
<height>26</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mnuFile">
Expand Down
1 change: 1 addition & 0 deletions images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
<file>images/expand_disabled.png</file>
<file>images/small_arrow.png</file>
<file>images/shadow.png</file>
<file>images/handle_small.png</file>
</qresource>
</RCC>
Binary file added images/handle_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f816b06

Please sign in to comment.