diff --git a/kcm/src/resolutionslider.h b/kcm/src/resolutionslider.h --- a/kcm/src/resolutionslider.h +++ b/kcm/src/resolutionslider.h @@ -49,6 +49,8 @@ void slotOutputModeChanged(); private: + void init(); + KScreen::OutputPtr mOutput; QList mModes; diff --git a/kcm/src/resolutionslider.cpp b/kcm/src/resolutionslider.cpp --- a/kcm/src/resolutionslider.cpp +++ b/kcm/src/resolutionslider.cpp @@ -47,16 +47,40 @@ { 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; } mModes << mode->size(); } 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 @@ 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(&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 @@ 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 @@ 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()) {