Commit 32e95fad authored by Andras Mantia's avatar Andras Mantia

Redraw the slider if modes have changed

Summary:
This can happen if a monitor was not configured at all, the KCM is shown
when it first plugged in and the user selects to not configure it.
In the UI it will appear with no Resolution/Refresh rate and wrong size in
the QML view.

Backport of D17658
Depends on D17685

Reviewers: #plasma, dvratil

Reviewed By: dvratil

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D17686
parent a244bfe1
......@@ -47,8 +47,20 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
{
connect(output.data(), &KScreen::Output::currentModeIdChanged,
this, &ResolutionSlider::slotOutputModeChanged);
connect(output.data(), &KScreen::Output::modesChanged,
this, &ResolutionSlider::init);
Q_FOREACH (const KScreen::ModePtr &mode, output->modes()) {
init();
}
ResolutionSlider::~ResolutionSlider()
{
}
void ResolutionSlider::init()
{
mModes.clear();
Q_FOREACH (const KScreen::ModePtr &mode, mOutput->modes()) {
if (mModes.contains(mode->size())) {
continue;
}
......@@ -57,6 +69,18 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
}
qSort(mModes.begin(), mModes.end(), sizeLessThan);
delete layout();
delete mSmallestLabel;
mSmallestLabel = nullptr;
delete mBiggestLabel;
mBiggestLabel = nullptr;
delete mCurrentLabel;
mCurrentLabel = nullptr;
delete mSlider;
mSlider = nullptr;
delete mComboBox;
mComboBox = nullptr;
QGridLayout *layout = new QGridLayout(this);
if (mModes.count() > 15) {
......@@ -66,14 +90,16 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
mComboBox->setEditable(false);
Q_FOREACH (const QSize &size, mModes) {
mComboBox->addItem(Utils::sizeToString(size));
if ((output->currentMode() && (output->currentMode()->size() == size))
|| (output->preferredMode() && (output->preferredMode()->size() == size))) {
if ((mOutput->currentMode() && (mOutput->currentMode()->size() == size))
|| (mOutput->preferredMode() && (mOutput->preferredMode()->size() == size))) {
mComboBox->setCurrentIndex(mComboBox->count() - 1);
}
}
layout->addWidget(mComboBox, 0, 0, 1, 1);
connect(mComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &ResolutionSlider::slotValueChanged);
this, &ResolutionSlider::slotValueChanged, Qt::UniqueConnection);
Q_EMIT resolutionChanged(mModes.at(mComboBox->currentIndex()));
} else {
mCurrentLabel = new QLabel(this);
mCurrentLabel->setAlignment(Qt::AlignCenter);
......@@ -92,10 +118,10 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
mSlider->setMinimum(0);
mSlider->setMaximum(mModes.size() - 1);
mSlider->setSingleStep(1);
if (output->currentMode()) {
mSlider->setValue(mModes.indexOf(output->currentMode()->size()));
} else if (output->preferredMode()) {
mSlider->setValue(mModes.indexOf(output->preferredMode()->size()));
if (mOutput->currentMode()) {
mSlider->setValue(mModes.indexOf(mOutput->currentMode()->size()));
} else if (mOutput->preferredMode()) {
mSlider->setValue(mModes.indexOf(mOutput->preferredMode()->size()));
} else {
mSlider->setValue(mSlider->maximum());
}
......@@ -110,15 +136,13 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
mBiggestLabel->setText(Utils::sizeToString(mModes.last()));
layout->addWidget(mBiggestLabel, 0, 2);
mCurrentLabel->setText(Utils::sizeToString(mModes.at(mSlider->value())));
const auto size = mModes.at(mSlider->value());
mCurrentLabel->setText(Utils::sizeToString(size));
Q_EMIT resolutionChanged(size);
}
}
}
ResolutionSlider::~ResolutionSlider()
{
}
QSize ResolutionSlider::currentResolution() const
{
if (mModes.isEmpty()) {
......
......@@ -49,6 +49,8 @@ class ResolutionSlider : public QWidget
void slotOutputModeChanged();
private:
void init();
KScreen::OutputPtr mOutput;
QList<QSize> mModes;
......
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