Commit d81633bb authored by Niklas Freund's avatar Niklas Freund
Browse files

Implemented Bitset scaling

parent b38dc4a7
......@@ -27,7 +27,8 @@ BitButton::BitButton(QWidget *parent)
size.setWidth(size.height());
}
setFixedSize(size);
setMinimumSize(size);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
this->setAttribute(Qt::WA_Hover, true);
}
......
......@@ -11,7 +11,7 @@
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -24,7 +24,7 @@
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="firstVerticalLayout" stretch="1,1,0,3">
<layout class="QVBoxLayout" name="firstVerticalLayout" stretch="2,1,0,6">
<item>
<widget class="KCalcDisplay" name="calc_display">
<property name="sizePolicy">
......@@ -44,10 +44,10 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<item>
<widget class="KCalcBitset" name="mBitset" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......
......@@ -42,8 +42,17 @@ void BitButton::paintEvent(QPaintEvent *)
if (over_) {
painter.setBrush(QColor(palette().text().color().red(), palette().text().color().green(), palette().text().color().blue(), alpha));
}
painter.drawRect(rect().adjusted(1, 1, -1, -1));
// Calculate button size (make it square)
QRectF square = rect();
if (square.width() > square.height())
square.setWidth(square.height());
else if (square.height() > square.width())
square.setHeight(square.width());
// Draw button
painter.translate(QPointF(0.0, (rect().height() - square.height()) / 2.0)); // center button
painter.drawRect(square.adjusted(1.0, 1.0, -1.0, -1.0));
}
//------------------------------------------------------------------------------
......@@ -84,6 +93,7 @@ KCalcBitset::KCalcBitset(QWidget *parent)
auto const tmpBitButton = new BitButton(this);
tmpBitButton->setToolTip(i18n("Bit %1 = %2", bitCounter, 1ULL << bitCounter));
wordlayout->addWidget(tmpBitButton);
wordlayout->setStretch(bit, 1);
bit_button_group_->addButton(tmpBitButton, bitCounter);
bitCounter--;
}
......@@ -93,7 +103,14 @@ KCalcBitset::KCalcBitset(QWidget *parent)
label->setText(QString::number(bitCounter + 1));
label->setFont(fnt);
wordlayout->addWidget(label);
wordlayout->setStretch(8, 1);
}
layout->setRowStretch(rows, 1);
}
// layout stretch for columns
for (int cols = 0; cols < 4; cols++) {
layout->setColumnStretch(cols, 1);
}
}
......
Supports Markdown
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