Skip to content

Commit

Permalink
Font size setting added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Sep 25, 2015
1 parent 36d907d commit eaaa67a
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 263 deletions.
23 changes: 14 additions & 9 deletions frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ frmMain::frmMain(QWidget *parent) :
m_currentDrawer = m_codeDrawer;
m_toolDrawer.setToolPosition(QVector3D(0, 0, 0));

foreach (StyledToolButton* button, ui->grpJog->findChildren<StyledToolButton*>(QRegExp("cmdJogStep\\d")))
{
connect(button, SIGNAL(clicked(bool)), this, SLOT(onCmdJogStepClicked()));
button->setChecked(button->text().toDouble() == ui->txtJogStep->value());
}

QShortcut *insertShortcut = new QShortcut(QKeySequence(Qt::Key_Insert), ui->tblProgram);
QShortcut *deleteShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), ui->tblProgram);

Expand Down Expand Up @@ -135,7 +129,13 @@ frmMain::frmMain(QWidget *parent) :
connect(&m_serialPort, SIGNAL(readyRead()), this, SLOT(onSerialPortReadyRead()));
connect(&m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialPortError(QSerialPort::SerialPortError)));

// Apply settings
// Apply settings
foreach (StyledToolButton* button, ui->grpJog->findChildren<StyledToolButton*>(QRegExp("cmdJogStep\\d")))
{
connect(button, SIGNAL(clicked(bool)), this, SLOT(onCmdJogStepClicked()));
button->setChecked(button->text().toDouble() == ui->txtJogStep->value());
}

show(); // Visibility bug workaround
applySettings();
updateControlsState();
Expand Down Expand Up @@ -200,6 +200,8 @@ void frmMain::loadSettings()
m_frmSettings.setPanelFeed(set.value("panelFeedVisible", true).toBool());
m_frmSettings.setPanelJog(set.value("panelJogVisible", true).toBool());

m_frmSettings.setFontSize(set.value("fontSize", 8).toInt());

ui->chkAutoScroll->setChecked(set.value("autoScroll", false).toBool());
ui->sliSpindleSpeed->setValue(set.value("spindleSpeed", 100).toInt() / 100);
ui->txtSpindleSpeed->setValue(set.value("spindleSpeed", 100).toInt());
Expand Down Expand Up @@ -322,6 +324,7 @@ void frmMain::saveSettings()
set.setValue("panelSpindleVisible", m_frmSettings.panelSpindle());
set.setValue("panelFeedVisible", m_frmSettings.panelFeed());
set.setValue("panelJogVisible", m_frmSettings.panelJog());
set.setValue("fontSize", m_frmSettings.fontSize());

set.setValue("heightmapBorderX", ui->txtHeightMapBorderX->value());
set.setValue("heightmapBorderY", ui->txtHeightMapBorderY->value());
Expand Down Expand Up @@ -415,8 +418,10 @@ void frmMain::updateControlsState() {
QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked
| QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed);

if (!portOpened) ui->txtStatus->setText(tr("Not connected"));
ui->txtStatus->setStyleSheet(QString("background-color: palette(button); color: palette(text);"));
if (!portOpened) {
ui->txtStatus->setText(tr("Not connected"));
ui->txtStatus->setStyleSheet(QString("background-color: palette(button); color: palette(text);"));
}

this->setWindowTitle(m_programFileName.isEmpty() ? "grblControl"
: m_programFileName.mid(m_programFileName.lastIndexOf("/") + 1) + " - grblControl");
Expand Down
24 changes: 18 additions & 6 deletions frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<normaloff>:/images/icon3png.png</normaloff>:/images/icon3png.png</iconset>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
<string notr="true">/*QWidget {
font-size: 9pt;
}
}*/

QSpinBox, QDoubleSpinBox {
padding-top: 1px;
Expand Down Expand Up @@ -1568,12 +1568,12 @@ QToolButton:checked { /* all types of tool button */
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>655</height>
<width>228</width>
<height>609</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -2241,11 +2241,17 @@ QDoubleSpinBox:focus {
</item>
<item row="0" column="3">
<layout class="QHBoxLayout" name="horizontalLayout_25">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
Expand Down Expand Up @@ -2290,11 +2296,17 @@ QDoubleSpinBox:focus {
</item>
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayout_26">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
Expand Down Expand Up @@ -2615,7 +2627,7 @@ QDoubleSpinBox:focus {
<x>0</x>
<y>0</y>
<width>870</width>
<height>23</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mnuFile">
Expand Down
20 changes: 20 additions & 0 deletions frmsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ frmSettings::frmSettings(QWidget *parent) :
ui->setupUi(this);
this->setLocale(QLocale::C);

m_intValidator.setBottom(1);
m_intValidator.setTop(999);
ui->cboFps->setValidator(&m_intValidator);
ui->cboFontSize->setValidator(&m_intValidator);

foreach (QGroupBox *box, this->findChildren<QGroupBox*>()) {
ui->listCategories->addItem(box->title());
ui->listCategories->item(ui->listCategories->count() - 1)->setData(Qt::UserRole, box->objectName());
Expand Down Expand Up @@ -409,6 +414,16 @@ QColor frmSettings::colors(QString name)
if (pick) return pick->color(); else return QColor();
}

int frmSettings::fontSize()
{
return ui->cboFontSize->currentText().toInt();
}

void frmSettings::setFontSize(int fontSize)
{
ui->cboFontSize->setCurrentText(QString::number(fontSize));
}

void frmSettings::showEvent(QShowEvent *se)
{
ui->scrollSettings->updateMinimumWidth();
Expand Down Expand Up @@ -495,3 +510,8 @@ void frmSettings::on_cmdDefaults_clicked()
ui->clpToolpathStart->setColor(QColor(255, 0, 0));
ui->clpToolpathEnd->setColor(QColor(0, 255, 0));
}

void frmSettings::on_cboFontSize_currentTextChanged(const QString &arg1)
{
qApp->setStyleSheet(QString(qApp->styleSheet()).replace(QRegExp("font-size:\\s*\\d+"), "font-size: " + arg1));
}
6 changes: 6 additions & 0 deletions frmsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class frmSettings : public QDialog
void setPanelJog(bool panelJog);
QList<ColorPicker*> colors();
QColor colors(QString name);
int fontSize();
void setFontSize(int fontSize);

protected:
void showEvent(QShowEvent *se);
Expand All @@ -98,6 +100,8 @@ private slots:

void on_cmdDefaults_clicked();

void on_cboFontSize_currentTextChanged(const QString &arg1);

private:
Ui::frmSettings *ui;
void searchPorts();
Expand All @@ -106,6 +110,8 @@ private slots:
QList<bool> m_storedChecks;
QList<QString> m_storedCombos;
QList<QColor> m_storedColors;

QIntValidator m_intValidator;
};

#endif // FRMSETTINGS_H
107 changes: 102 additions & 5 deletions frmsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<string>Settings</string>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
<string notr="true">/*QWidget {
font-size: 9pt;
}
}*/

QSpinBox, QDoubleSpinBox {
padding-top: 1px;
Expand Down Expand Up @@ -83,9 +83,9 @@ QGroupBox {
<property name="geometry">
<rect>
<x>0</x>
<y>-549</y>
<width>344</width>
<height>998</height>
<y>-522</y>
<width>336</width>
<height>963</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
Expand Down Expand Up @@ -663,6 +663,9 @@ padding-top: 3;</string>
</item>
<item>
<widget class="QComboBox" name="cboFps">
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly|Qt::ImhFormattedNumbersOnly</set>
</property>
<property name="editable">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -1059,6 +1062,100 @@ padding-top: 3;</string>
</layout>
</widget>
</item>
<item>
<widget class="GroupBox" name="groupBox">
<property name="title">
<string>Font</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_29">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboFontSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string>-1</string>
</property>
<property name="maxCount">
<number>10</number>
</property>
<property name="minimumContentsLength">
<number>1</number>
</property>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>11</string>
</property>
</item>
<item>
<property name="text">
<string>12</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_30">
<property name="text">
<string>pt</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_31">
<property name="styleSheet">
<string notr="true">color: blue;</string>
</property>
<property name="text">
<string>(restart needed)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
1 change: 1 addition & 0 deletions glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void GLWidget::setColorBackground(const QColor &colorBackground)

void GLWidget::setFps(int fps)
{
if (fps <= 0) return;
m_targetFps = fps;
m_timerAnimation.stop();
m_timerAnimation.start(1000 / fps, Qt::PreciseTimer, this);
Expand Down
16 changes: 12 additions & 4 deletions groupbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ void GroupBox::mouseMoveEvent(QMouseEvent *event)
{
QGroupBox::mouseMoveEvent(event);

QPoint delta = event->globalPos() - m_pressedPos;

emit mouseMoved(delta.x(), delta.y());
if (!m_pressedPos.isNull()) {
QPoint delta = event->globalPos() - m_pressedPos;
emit mouseMoved(delta.x(), delta.y());
}
}

void GroupBox::mousePressEvent(QMouseEvent *event)
{
QGroupBox::mousePressEvent(event);
m_pressedPos = event->globalPos();

m_pressedPos = event->globalPos();
emit mousePressed();
}

void GroupBox::mouseReleaseEvent(QMouseEvent *event)
{
QGroupBox::mouseReleaseEvent(event);

m_pressedPos = QPoint();
}

1 change: 1 addition & 0 deletions groupbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GroupBox : public QGroupBox
protected:
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);

private:
QPoint m_pressedPos;
Expand Down
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ int main(int argc, char *argv[])
QDialog {border: 1px solid palette(mid);}");
#endif

a.setStyleSheet(a.styleSheet() + "QWidget {font-size: 8pt}");

frmMain w;
w.show();

Expand Down
Loading

0 comments on commit eaaa67a

Please sign in to comment.