2 * Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
3 * Copyright (c) 2002 Hamish Rodda <rodda@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "legacyrandrconfig.h"
22 #include <QRadioButton>
23 #include "randrdisplay.h"
24 #include "legacyrandrscreen.h"
26 LegacyRandRConfig::LegacyRandRConfig(QWidget
*parent
, RandRDisplay
*display
)
27 : QWidget(parent
), Ui::LegacyRandRConfigBase()
33 if (!m_display
->isValid())
36 for (int s
= 0; s
< m_display
->numScreens(); ++s
)
37 screenCombo
->addItem(i18n("Screen %1", s
+1));
38 screenCombo
->setCurrentIndex(m_display
->currentScreenIndex());
40 if (m_display
->numScreens() <= 1)
41 screenCombo
->setEnabled(false);
43 new QGridLayout(rotationGroup
);
45 for (int i
= 0; i
< RandR::OrientationCount
; i
++)
46 addRotationButton(1 << i
, i
> RandR::RotationCount
- 1);
49 connect(screenCombo
, SIGNAL(activated(int)), SLOT(slotScreenChanged(int)));
50 connect(sizeCombo
, SIGNAL(activated(int)), SLOT(slotSizeChanged(int)));
51 connect(rateCombo
, SIGNAL(activated(int)), SLOT(slotRefreshChanged(int)));
52 connect(applyOnStartup
, SIGNAL(clicked()), SLOT(setChanged()));
53 connect(syncTrayApp
, SIGNAL(clicked()), SLOT(setChanged()));
56 syncTrayApp
->setEnabled(applyOnStartup
->isChecked());
58 slotScreenChanged(m_display
->currentScreenIndex());
61 LegacyRandRConfig::~LegacyRandRConfig()
65 void LegacyRandRConfig::load()
67 if (!m_display
->isValid())
70 // Don't load screen configurations:
71 // It will be correct already if they wanted to retain their settings over KDE restarts,
72 // and if it isn't correct they have changed a) their X configuration, b) the screen
73 // with another program, or c) their hardware.
75 KConfig
config("krandrrc");
76 m_oldApply
= m_display
->loadDisplay(config
, false);
77 m_oldSyncTrayApp
= m_display
->syncTrayApp(config
);
78 applyOnStartup
->setChecked(m_oldApply
);
79 syncTrayApp
->setChecked(m_oldSyncTrayApp
);
84 void LegacyRandRConfig::save()
86 if (!m_display
->isValid())
91 m_oldApply
= applyOnStartup
->isChecked();
92 m_oldSyncTrayApp
= syncTrayApp
->isChecked();
93 KConfig
config("krandrrc");
94 m_display
->saveDisplay(config
, m_oldApply
, m_oldSyncTrayApp
);
99 void LegacyRandRConfig::defaults()
101 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
104 if (screen
->changedFromOriginal()) {
105 screen
->proposeOriginal();
106 screen
->applyProposed();
108 screen
->proposeOriginal();
114 void LegacyRandRConfig::slotScreenChanged(int screenId
)
116 m_display
->setCurrentScreen(screenId
);
121 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
124 // Add new resolutions
125 for (int i
= 0; i
< screen
->numSizes(); i
++) {
126 sizeCombo
->addItem(QString("%1 x %2").arg(screen
->pixelSize(i
).width()).arg(screen
->pixelSize(i
).height()));
129 /* , aspect ratio %5)*/
130 /*.arg((double)currentScreen()->size(i).mwidth / (double)currentScreen()->size(i).mheight))*/
133 // configure the possible rotations
134 for (int i
= 0; i
< RandR::OrientationCount
; i
++)
135 m_rotationGroup
.button(1 << i
)->setEnabled( (1 << i
) & screen
->rotations());
137 m_rotationGroup
.button(screen
->rotation())->setChecked(true);
138 populateRefreshRates();
145 void LegacyRandRConfig::slotRotationChanged()
147 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
150 //FIXME: need to check this later
151 int id
= m_rotationGroup
.checkedId();
153 screen
->proposeRotation(id
);
157 void LegacyRandRConfig::slotSizeChanged(int index
)
159 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
162 int oldProposed
= screen
->proposedSize();
164 screen
->proposeSize(index
);
166 if (screen
->proposedSize() != oldProposed
) {
167 screen
->proposeRefreshRate(0);
169 populateRefreshRates();
171 // Item with index zero is already selected
177 void LegacyRandRConfig::slotRefreshChanged(int index
)
179 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
182 screen
->proposeRefreshRate(index
);
187 void LegacyRandRConfig::setChanged()
189 bool isChanged
= (m_oldApply
!= applyOnStartup
->isChecked()) || (m_oldSyncTrayApp
!= syncTrayApp
->isChecked());
190 syncTrayApp
->setEnabled(applyOnStartup
->isChecked());
193 for (int screenIndex
= 0; screenIndex
< m_display
->numScreens(); screenIndex
++) {
194 if (m_display
->legacyScreen(screenIndex
)->proposedChanged()) {
200 if (isChanged
!= m_changed
) {
201 m_changed
= isChanged
;
202 emit
changed(m_changed
);
206 void LegacyRandRConfig::apply()
209 m_display
->applyProposed();
215 void LegacyRandRConfig::update()
217 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
220 sizeCombo
->blockSignals(true);
221 sizeCombo
->setCurrentIndex(screen
->proposedSize());
222 sizeCombo
->blockSignals(false);
224 m_rotationGroup
.blockSignals(true);
225 m_rotationGroup
.button(screen
->proposedRotation())->setChecked(true);
227 //m_rotationGroup.button(4)->setDown(screen->proposedRotation() & RandR::ReflectX);
228 //m_rotationGroup.button(5)->setDown(screen->proposedRotation() & RandR::ReflectY);
229 m_rotationGroup
.blockSignals(false);
231 rateCombo
->blockSignals(true);
232 rateCombo
->setCurrentIndex(screen
->proposedRefreshRate());
233 rateCombo
->blockSignals(false);
236 void LegacyRandRConfig::addRotationButton(int thisRotation
, bool checkbox
)
238 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
242 QRadioButton
* thisButton
= new QRadioButton(RandR::rotationName(thisRotation
), rotationGroup
);
243 m_rotationGroup
.addButton( thisButton
, thisRotation
);
244 thisButton
->setEnabled(thisRotation
& screen
->rotations());
245 connect(thisButton
, SIGNAL(clicked()), SLOT(slotRotationChanged()));
246 rotationGroup
->layout()->addWidget(thisButton
);
248 QCheckBox
* thisButton
= new QCheckBox(RandR::rotationName(thisRotation
), rotationGroup
);
249 m_rotationGroup
.addButton( thisButton
, thisRotation
);
250 thisButton
->setEnabled(thisRotation
& screen
->rotations());
251 connect(thisButton
, SIGNAL(clicked()), SLOT(slotRotationChanged()));
252 rotationGroup
->layout()->addWidget(thisButton
);
256 void LegacyRandRConfig::populateRefreshRates()
258 LegacyRandRScreen
*screen
= m_display
->currentLegacyScreen();
263 RateList rr
= screen
->refreshRates(screen
->proposedSize());
265 rateCombo
->setEnabled(rr
.count());
267 foreach(float rate
, rr
)
269 rateCombo
->addItem(ki18n("%1 Hz").subs(rate
, 0, 'f', 1).toString(), rate
);
273 #include "legacyrandrconfig.moc"