Skip to content

Commit

Permalink
Allow fixed custom size for QTerminal
Browse files Browse the repository at this point in the history
Closes #492

If the window size is not remembered on exiting, the custom width and height could be set in Preferences. Then, QTerminal will always have that size on starting. Of course, the maximized state is also saved/restored, as before.

Although the size is in pixels (not in characters), a button is added for getting the current size, so that the user could first resize QTerminal and then open Preferences and get the size. In this way, (1) lots of complex calculations are prevented, and (2) differences in tastes are respected.
  • Loading branch information
tsujan authored and agaida committed Aug 18, 2019
1 parent 01a6cf7 commit c8c0648
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 21 deletions.
66 changes: 62 additions & 4 deletions src/forms/propertiesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -601,7 +601,7 @@
</property>
</spacer>
</item>
<item row="8" column="0" colspan="3">
<item row="9" column="0" colspan="3">
<widget class="QCheckBox" name="useCwdCheckBox">
<property name="text">
<string>Open new terminals in current working directory</string>
Expand Down Expand Up @@ -646,14 +646,14 @@
</property>
</widget>
</item>
<item row="9" column="0">
<item row="10" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Default $TERM</string>
</property>
</widget>
</item>
<item row="9" column="2">
<item row="10" column="2">
<widget class="QComboBox" name="termComboBox">
<property name="editable">
<bool>true</bool>
Expand All @@ -673,6 +673,64 @@
</item>
</widget>
</item>
<item row="8" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="fixedSizeLabel">
<property name="text">
<string>Start with this size:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="fixedWithSpinBox">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="xLabel">
<property name="text">
<string notr="true">×</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="fixedHeightSpinBox">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fixedSizeButton">
<property name="text">
<string>Get current size</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
8 changes: 6 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ MainWindow::MainWindow(TerminalConfig &cfg,
setStyleSheet(QStringLiteral(QSS_DROP));
}
else {
if (Properties::Instance()->saveSizeOnExit && Properties::Instance()->mainWindowSize.isValid()) {
resize(Properties::Instance()->mainWindowSize);
if (Properties::Instance()->saveSizeOnExit) {
if (Properties::Instance()->mainWindowSize.isValid())
resize(Properties::Instance()->mainWindowSize);
}
else if (Properties::Instance()->fixedWindowSize.isValid()) {
resize(Properties::Instance()->fixedWindowSize);
}
if (Properties::Instance()->savePosOnExit && !Properties::Instance()->mainWindowPosition.isNull()) {
move(Properties::Instance()->mainWindowPosition);
Expand Down
2 changes: 2 additions & 0 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void Properties::loadSettings()
font = qvariant_cast<QFont>(m_settings->value(QLatin1String("font"), font));

mainWindowSize = m_settings->value(QLatin1String("MainWindow/size")).toSize();
fixedWindowSize = m_settings->value(QLatin1String("MainWindow/fixedSize"), QSize(600, 400)).toSize().expandedTo(QSize(300, 200));
mainWindowPosition = m_settings->value(QLatin1String("MainWindow/pos")).toPoint();
mainWindowState = m_settings->value(QLatin1String("MainWindow/state")).toByteArray();

Expand Down Expand Up @@ -182,6 +183,7 @@ void Properties::saveSettings()
m_settings->endGroup();

m_settings->setValue(QLatin1String("MainWindow/size"), mainWindowSize);
m_settings->setValue(QLatin1String("MainWindow/fixedSize"), fixedWindowSize);
m_settings->setValue(QLatin1String("MainWindow/pos"), mainWindowPosition);
m_settings->setValue(QLatin1String("MainWindow/state"), mainWindowState);

Expand Down
1 change: 1 addition & 0 deletions src/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Properties
void migrate_settings();

QSize mainWindowSize;
QSize fixedWindowSize;
QPoint mainWindowPosition;
QByteArray mainWindowState;
//ShortcutMap shortcuts;
Expand Down
59 changes: 44 additions & 15 deletions src/propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ PropertiesDialog::PropertiesDialog(QWidget *parent)
connect(chooseBackgroundImageButton, &QPushButton::clicked,
this, &PropertiesDialog::chooseBackgroundImageButton_clicked);

// fixed size
connect(saveSizeOnExitCheckBox, &QCheckBox::stateChanged, [this] (int state) {
fixedSizeLabel->setEnabled(state == Qt::Unchecked);
xLabel->setEnabled(state == Qt::Unchecked);
fixedWithSpinBox->setEnabled(state == Qt::Unchecked);
fixedHeightSpinBox->setEnabled(state == Qt::Unchecked);
fixedSizeButton->setEnabled(state == Qt::Unchecked);
});
connect(fixedSizeButton, &QAbstractButton::clicked, [this, parent] {
if (parent != nullptr)
{
QSize pSize = parent->window()->geometry().size();
fixedWithSpinBox->setValue(pSize.width());
fixedHeightSpinBox->setValue(pSize.height());
}
});
fixedWithSpinBox->setMinimum(300);
fixedHeightSpinBox->setMinimum(200);
QSize ag;
if (parent != nullptr)
{
if (QWindow *win = parent->windowHandle())
{
if (QScreen *sc = win->screen())
{
ag = sc->availableVirtualGeometry().size()
// also consider the parent frame thickness because the parent window is fully formed
- (parent->window()->frameGeometry().size()
- parent->window()->geometry().size());
}
}
}
if (ag.isValid())
{
fixedWithSpinBox->setMaximum(ag.width());
fixedHeightSpinBox->setMaximum(ag.height());
}

QStringList emulations = QTermWidget::availableKeyBindings();
QStringList colorSchemes = QTermWidget::availableColorSchemes();
colorSchemes.sort(Qt::CaseInsensitive);
Expand Down Expand Up @@ -157,6 +195,8 @@ PropertiesDialog::PropertiesDialog(QWidget *parent)

savePosOnExitCheckBox->setChecked(Properties::Instance()->savePosOnExit);
saveSizeOnExitCheckBox->setChecked(Properties::Instance()->saveSizeOnExit);
fixedWithSpinBox->setValue(Properties::Instance()->fixedWindowSize.width());
fixedHeightSpinBox->setValue(Properties::Instance()->fixedWindowSize.height());

useCwdCheckBox->setChecked(Properties::Instance()->useCWD);

Expand Down Expand Up @@ -191,21 +231,9 @@ PropertiesDialog::PropertiesDialog(QWidget *parent)
trimPastedTrailingNewlinesCheckBox->setChecked(Properties::Instance()->trimPastedTrailingNewlines);
confirmMultilinePasteCheckBox->setChecked(Properties::Instance()->confirmMultilinePaste);

// show it inside available desktop geometry
QSize ag;
if (parent != nullptr)
{
if (QWindow *win = parent->windowHandle())
{
if (QScreen *sc = win->screen())
ag = sc->availableVirtualGeometry().size()
// also consider the parent frame thickness because the parent window
// is fully formed and the frame thickness of the dialog is the same
- (parent->window()->frameGeometry().size()
- parent->window()->geometry().size());
}
}
resize(size().boundedTo(ag));
// fit it into available desktop geometry
if (ag.isValid())
resize(size().boundedTo(ag));
}


Expand Down Expand Up @@ -244,6 +272,7 @@ void PropertiesDialog::apply()

Properties::Instance()->savePosOnExit = savePosOnExitCheckBox->isChecked();
Properties::Instance()->saveSizeOnExit = saveSizeOnExitCheckBox->isChecked();
Properties::Instance()->fixedWindowSize = QSize(fixedWithSpinBox->value(), fixedHeightSpinBox->value()).expandedTo(QSize(300, 200)); // FIXME: make Properties variables private and use public methods for setting/getting them

Properties::Instance()->useCWD = useCwdCheckBox->isChecked();

Expand Down

0 comments on commit c8c0648

Please sign in to comment.