- Timestamp:
- Oct 15, 2018 8:57:13 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp
r74757 r74837 408 408 /* Load old 'Screen' data from the cache: */ 409 409 m_pEditorVideoScreenCount->setValue(oldDisplayData.m_cGuestScreenCount); 410 m_pScaleFactorEditor->setScaleFactors(oldDisplayData.m_scaleFactors); 410 411 m_pScaleFactorEditor->setMonitorCount(oldDisplayData.m_cGuestScreenCount); 411 m_pScaleFactorEditor->setScaleFactors(oldDisplayData.m_scaleFactors);412 412 m_pCheckbox3D->setChecked(oldDisplayData.m_f3dAccelerationEnabled); 413 413 #ifdef VBOX_WITH_VIDEOHWACCEL -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIScaleFactorEditor.cpp
r74757 r74837 43 43 , m_pMaxScaleLabel(0) 44 44 , m_pMinScaleLabel(0) 45 , m_dDefaultScaleFactor(1.0) 45 46 { 46 47 /* Prepare: */ 47 48 prepare(); 49 /* Append a default scale factor to the list as an global scale factor: */ 50 m_scaleFactors.append(1.0); 48 51 } 49 52 … … 52 55 if (!m_pMonitorComboBox) 53 56 return; 54 if (iMonitorCount == m_pMonitorComboBox->count()) 55 return; 56 57 /* We always have 0th for global scale factor (in combo box and scale factor list): */ 58 int iEndMonitorCount = iMonitorCount + 1; 59 int iCurrentMonitorCount = m_pMonitorComboBox->count(); 60 if (iEndMonitorCount == iCurrentMonitorCount) 61 return; 62 m_pMonitorComboBox->setEnabled(iMonitorCount > 1); 57 63 m_pMonitorComboBox->blockSignals(true); 58 int iCurrentMonitorCount = m_pMonitorComboBox->count();59 64 int iCurrentMonitorIndex = m_pMonitorComboBox->currentIndex(); 60 //m_pMonitorComboBox->clear(); 61 if (iCurrentMonitorCount < iMonitorCount) 62 { 63 for (int i = iCurrentMonitorCount; i < iMonitorCount; ++i) 64 { 65 m_pMonitorComboBox->addItem(QString("Monitor %1").arg(i)); 66 /* In case that we have increased the # of monitors add new scale factors to the scale factor cache: */ 67 if (i >= m_scaleFactors.size()) 68 m_scaleFactors.append(1.0); 69 } 65 if (iCurrentMonitorCount < iEndMonitorCount) 66 { 67 for (int i = iCurrentMonitorCount; i < iEndMonitorCount; ++i) 68 m_pMonitorComboBox->insertItem(i, QString("Monitor %1").arg(i)); 70 69 } 71 70 else 72 71 { 73 for (int i = iCurrentMonitorCount - 1; i >= i MonitorCount; --i)72 for (int i = iCurrentMonitorCount - 1; i >= iEndMonitorCount; --i) 74 73 m_pMonitorComboBox->removeItem(i); 75 74 } 75 m_pMonitorComboBox->setEnabled(iMonitorCount > 1); 76 if (iMonitorCount <= 1) 77 m_pMonitorComboBox->setCurrentIndex(0); 76 78 m_pMonitorComboBox->blockSignals(false); 77 79 /* Update the slider and spinbox values if the combobox index has changed: */ 78 80 if (iCurrentMonitorIndex != m_pMonitorComboBox->currentIndex()) 79 showMonitorScaleFactor();81 updateValuesAfterMonitorChange(); 80 82 } 81 83 82 84 void UIScaleFactorEditor::setScaleFactors(const QList<double> &scaleFactors) 83 85 { 84 if (m_scaleFactors == scaleFactors) 85 return; 86 /* if m_scaleFactors has more items than @p scaleFactors than we keep the additional items 87 this can happen for example when extra data has 4 scale factor while machine has 5 monitors: */ 88 if (m_scaleFactors.size() > scaleFactors.size()) 89 { 90 for (int i = 0; i < scaleFactors.size(); ++i) 91 m_scaleFactors[i] = scaleFactors[i]; 86 m_scaleFactors.clear(); 87 /* If we have a single value from the extra data and we treat if as a default scale factor: */ 88 if (scaleFactors.size() == 1) 89 { 90 m_dDefaultScaleFactor = scaleFactors.at(0); 91 m_scaleFactors.append(m_dDefaultScaleFactor); 92 isGlobalScaleFactor(true); 93 return; 94 } 95 96 // Insert 0th element as the global scalar value 97 m_scaleFactors.append(m_dDefaultScaleFactor); 98 m_scaleFactors.append(scaleFactors); 99 isGlobalScaleFactor(false); 100 } 101 102 QList<double> UIScaleFactorEditor::scaleFactors() const 103 { 104 QList<double> scaleFactorList; 105 if (m_scaleFactors.size() == 0) 106 return scaleFactorList; 107 108 /* Decide if the users wants a global (not per monitor) scaling. */ 109 bool globalScaleFactor = false; 110 111 /* if "All Monitors" item is selected in the combobox: */ 112 if (m_pMonitorComboBox && m_pMonitorComboBox->currentIndex() == 0) 113 globalScaleFactor = true; 114 /* Also check if all of the monitor scale factors equal to the global scale factor: */ 115 if (!globalScaleFactor) 116 { 117 globalScaleFactor = true; 118 for (int i = 1; i < m_scaleFactors.size() && globalScaleFactor; ++i) 119 if (m_scaleFactors[0] != m_scaleFactors[i]) 120 globalScaleFactor = false; 121 } 122 123 if (globalScaleFactor) 124 { 125 scaleFactorList << m_scaleFactors.at(0); 92 126 } 93 127 else 94 128 { 95 m_scaleFactors = scaleFactors; 96 } 97 showMonitorScaleFactor(); 98 } 99 100 101 const QList<double>& UIScaleFactorEditor::scaleFactors() const 102 { 103 return m_scaleFactors; 129 /* Skip the 0th scale factor: */ 130 for (int i = 1; i < m_scaleFactors.size(); ++i) 131 scaleFactorList.append(m_scaleFactors.at(i)); 132 } 133 134 return scaleFactorList; 135 } 136 137 void UIScaleFactorEditor::isGlobalScaleFactor(bool bFlag) 138 { 139 if (!m_pMonitorComboBox) 140 return; 141 if (bFlag && m_pMonitorComboBox->count() >= 1) 142 m_pMonitorComboBox->setCurrentIndex(0); 143 else 144 if(m_pMonitorComboBox->count() >= 2) 145 m_pMonitorComboBox->setCurrentIndex(1); 146 updateValuesAfterMonitorChange(); 147 } 148 149 void UIScaleFactorEditor::setDefaultScaleFactor(double dDefaultScaleFactor) 150 { 151 m_dDefaultScaleFactor = dDefaultScaleFactor; 104 152 } 105 153 … … 107 155 { 108 156 if (m_pMaxScaleLabel) 109 {110 157 m_pMaxScaleLabel->setText(tr("Max")); 111 }112 158 113 159 if (m_pMinScaleLabel) 114 {115 160 m_pMinScaleLabel->setText(tr("Min")); 116 } 161 162 if (m_pMonitorComboBox && m_pMonitorComboBox->count() > 0) 163 { 164 m_pMonitorComboBox->setItemText(0, tr("All Monitors")); 165 for (int i = 0; i < m_pMonitorComboBox->count(); ++i) 166 m_pMonitorComboBox->setItemText(i, tr("Monitor(%1)").arg(i)); 167 } 168 setToolTip(tr("Controls the guest screen scale factor")); 117 169 } 118 170 … … 131 183 } 132 184 133 void UIScaleFactorEditor::sltMonitorComboIndexChanged(int index) 134 { 135 if (index >= m_scaleFactors.size()) 136 return; 137 138 /* Update the slider and spinbox values without emitting signals: */ 139 int scaleFactor = 100 * m_scaleFactors[index]; 140 setSliderValue(scaleFactor); 141 setSpinBoxValue(scaleFactor); 185 void UIScaleFactorEditor::sltMonitorComboIndexChanged(int) 186 { 187 updateValuesAfterMonitorChange(); 142 188 } 143 189 … … 153 199 { 154 200 m_pMainLayout->addWidget(m_pMonitorComboBox, 0, 0); 201 m_pMonitorComboBox->insertItem(0, "All Monitors"); 155 202 connect(m_pMonitorComboBox ,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 156 203 this, &UIScaleFactorEditor::sltMonitorComboIndexChanged); … … 203 250 void UIScaleFactorEditor::setScaleFactor(int iMonitorIndex, int iScaleFactor) 204 251 { 205 /* Make sure we have the corresponding scale value for the @p iMonitorIndex: */206 if ( iMonitorIndex >=m_scaleFactors.size())207 { 208 for (int i = m_scaleFactors.size(); i < = iMonitorIndex; ++i)209 m_scaleFactors.append( 1.0);252 /* Make sure we have the corresponding scale values for all monitors: */ 253 if (m_pMonitorComboBox->count() > m_scaleFactors.size()) 254 { 255 for (int i = m_scaleFactors.size(); i < m_pMonitorComboBox->count(); ++i) 256 m_scaleFactors.append(m_dDefaultScaleFactor); 210 257 } 211 258 m_scaleFactors[iMonitorIndex] = iScaleFactor / 100.0; … … 232 279 } 233 280 234 void UIScaleFactorEditor:: showMonitorScaleFactor()281 void UIScaleFactorEditor::updateValuesAfterMonitorChange() 235 282 { 236 283 /* Set the spinbox value for the currently selected monitor: */ … … 238 285 { 239 286 int currentMonitorIndex = m_pMonitorComboBox->currentIndex(); 240 if (m_scaleFactors.size() > currentMonitorIndex && m_pScaleSpinBox) 241 { 242 setSpinBoxValue(100 * m_scaleFactors.at(currentMonitorIndex)); 243 setSliderValue(100 * m_scaleFactors.at(currentMonitorIndex)); 244 } 245 } 246 } 287 while (m_scaleFactors.size() <= currentMonitorIndex) 288 m_scaleFactors.append(m_dDefaultScaleFactor); 289 290 setSpinBoxValue(100 * m_scaleFactors.at(currentMonitorIndex)); 291 setSliderValue(100 * m_scaleFactors.at(currentMonitorIndex)); 292 293 } 294 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIScaleFactorEditor.h
r74757 r74837 35 35 class QIAdvancedSlider; 36 36 37 /** QWidget reimplementation 38 * providing GUI with monitor scale factor editing functionality. */ 37 /** QWidget reimplementation providing GUI with monitor scale factor editing functionality. 38 * It includes a combo box to select a monitor, a slider, and a spinbox to display/modify values. 39 * The first item in the combo box is used to change the scale factor of all monitors.*/ 39 40 class SHARED_LIBRARY_STUFF UIScaleFactorEditor : public QIWithRetranslateUI<QWidget> 40 41 { … … 43 44 public: 44 45 45 /** Constructor, passes @a pParent to the QWidget constructor.*/46 46 UIScaleFactorEditor(QWidget *pParent); 47 void setMonitorCount(int iMonitorCount); 48 void setScaleFactors(const QList<double> &scaleFactors); 49 const QList<double>& scaleFactors() const; 47 void setMonitorCount(int iMonitorCount); 48 void setScaleFactors(const QList<double> &scaleFactors); 49 /* Returns either a single global scale factor or a list of scale factor for each monitor. */ 50 QList<double> scaleFactors() const; 51 52 void isGlobalScaleFactor(bool bFlag); 53 void setDefaultScaleFactor(double dDefaultScaleFactor); 50 54 51 55 protected: … … 68 72 void setSpinBoxValue(int iValue); 69 73 /* Set the spinbox and slider to scale factor of currently selected monitor */ 70 void showMonitorScaleFactor();74 void updateValuesAfterMonitorChange(); 71 75 QSpinBox *m_pScaleSpinBox; 72 76 QGridLayout *m_pMainLayout; … … 75 79 QLabel *m_pMaxScaleLabel; 76 80 QLabel *m_pMinScaleLabel; 77 /* Stores the per-monitor scale factors in range [.., 1, ..]*/81 /* Stores the per-monitor scale factors. The 0th item is for all monitors (global) */ 78 82 QList<double> m_scaleFactors; 83 double m_dDefaultScaleFactor; 79 84 }; 80 85
Note:
See TracChangeset
for help on using the changeset viewer.