Commit 4c4d136f authored by Niklas Freund's avatar Niklas Freund
Browse files

Mostly fixed bitset button drifting

parent c4ae4fde
......@@ -2143,6 +2143,7 @@ void KCalculator::showScienceButtons(bool toggled)
void KCalculator::showLogicButtons(bool toggled)
{
if (toggled) {
firstVerticalLayout->setStretch(1, 1);
mBitset->setEnabled(true);
connect(mBitset, &KCalcBitset::valueChanged, this, &KCalculator::slotBitsetChanged);
connect(calc_display, &KCalcDisplay::changedAmount, this, &KCalculator::slotUpdateBitset);
......@@ -2168,6 +2169,7 @@ void KCalculator::showLogicButtons(bool toggled)
(num_button_group_->button(i))->show();
}
} else {
firstVerticalLayout->setStretch(1, 0);
mBitset->setEnabled(false);
disconnect(mBitset, &KCalcBitset::valueChanged, this, &KCalculator::slotBitsetChanged);
disconnect(calc_display, &KCalcDisplay::changedAmount, this, &KCalculator::slotUpdateBitset);
......@@ -2676,6 +2678,9 @@ void KCalculator::resizeEvent(QResizeEvent* event)
// Adjust button fonts
setFonts();
// Force mBitset to call its resizeEvent
mBitset->resize(0, 0);
}
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1346</width>
<height>350</height>
<height>352</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -45,17 +45,21 @@
</widget>
</item>
<item>
<widget class="KCalcBitset" name="mBitset" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Click on a Bit to toggle it.</string>
</property>
</widget>
<layout class="QHBoxLayout" name="bitsetHelper">
<item>
<widget class="KCalcBitset" name="mBitset" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Click on a Bit to toggle it.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
......
......@@ -110,6 +110,14 @@ KCalcBitset::KCalcBitset(QWidget *parent)
for (int cols = 0; cols < 4; cols++) {
layout->setColumnStretch(cols, 1);
}
// store current aspect ratio (using width:height)
QSize initialSize(size());
if (initialSize.height() != 0.0 && float(initialSize.width()) / float(initialSize.height()) < 2.5) {
ratio_ = float(initialSize.width()) / float(initialSize.height());
} else {
ratio_ = 1.355163727959698; // 538/397
}
}
//------------------------------------------------------------------------------
......@@ -165,7 +173,26 @@ void KCalcBitset::resizeEvent(QResizeEvent *event)
{
// Call the overridden resize event
QFrame::resizeEvent(event);
// Set our maximum size based on the space available in the parent (to keep aspect ratio)
QWidget *parent = parentWidget();
if (parent) {
QSize maxSize(parent->contentsRect().width(), parent->contentsRect().height());
if (maxSize.width() != 0 && maxSize.height() != 0) {
float actualRatio = float(maxSize.width()) / float(maxSize.height());
if (actualRatio > ratio_) {
// available space is too wide, limit width
maxSize.setWidth(ratio_ * maxSize.height());
} else if (actualRatio < ratio_) {
// available space is too tall, limit height
maxSize.setHeight(maxSize.width() / ratio_);
}
setMaximumSize(maxSize.width(), maxSize.height());
}
}
// Get the minimum size of all buttons
int minWidth = INT_MAX;
int minHeight = INT_MAX;
......@@ -194,4 +221,6 @@ void KCalcBitset::resizeEvent(QResizeEvent *event)
}
}
}
updateGeometry();
}
......@@ -32,5 +32,6 @@ Q_SIGNALS:
private:
QButtonGroup *const bit_button_group_;
quint64 value_;
float ratio_;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment