vbox的更動 72197 路徑 trunk/src/VBox/Debugger/VBoxDbgConsole.cpp
- 時間撮記:
- 2018-5-11 下午10:11:22 (7 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Debugger/VBoxDbgConsole.cpp
r69500 r72197 57 57 */ 58 58 59 /*static*/ const uint32_t VBoxDbgConsoleOutput::s_uMinFontSize = 6; 60 59 61 60 62 VBoxDbgConsoleOutput::VBoxDbgConsoleOutput(QWidget *pParent/* = NULL*/, IVirtualBox *a_pVirtualBox /* = NULL */, … … 72 74 73 75 /* 74 * Font. 76 * Create actions for color-scheme menu items. 77 */ 78 m_pGreenOnBlackAction = new QAction(tr("Green On Black"), this); 79 m_pGreenOnBlackAction->setCheckable(true); 80 m_pGreenOnBlackAction->setShortcut(Qt::ControlModifier + Qt::Key_1); 81 m_pGreenOnBlackAction->setData((int)kGreenOnBlack); 82 connect(m_pGreenOnBlackAction, SIGNAL(triggered()), this, SLOT(sltSelectColorScheme())); 83 84 m_pBlackOnWhiteAction = new QAction(tr("Black On White"), this); 85 m_pBlackOnWhiteAction->setCheckable(true); 86 m_pBlackOnWhiteAction->setShortcut(Qt::ControlModifier + Qt::Key_2); 87 m_pBlackOnWhiteAction->setData((int)kBlackOnWhite); 88 connect(m_pBlackOnWhiteAction, SIGNAL(triggered()), this, SLOT(sltSelectColorScheme())); 89 90 /* Create action group for grouping of exclusive color-scheme menu items. */ 91 QActionGroup *pActionColorGroup = new QActionGroup(this); 92 pActionColorGroup->addAction(m_pGreenOnBlackAction); 93 pActionColorGroup->addAction(m_pBlackOnWhiteAction); 94 pActionColorGroup->setExclusive(true); 95 96 /* 75 97 * Create actions for font menu items. 76 98 */ … … 78 100 m_pCourierFontAction->setCheckable(true); 79 101 m_pCourierFontAction->setShortcut(Qt::ControlModifier + Qt::Key_D); 80 connect(m_pCourierFontAction, SIGNAL(triggered()), this, SLOT(setFontCourier())); 102 m_pCourierFontAction->setData((int)kFontType_Courier); 103 connect(m_pCourierFontAction, SIGNAL(triggered()), this, SLOT(sltSelectFontType())); 81 104 82 105 m_pMonospaceFontAction = new QAction(tr("Monospace"), this); 83 106 m_pMonospaceFontAction->setCheckable(true); 84 107 m_pMonospaceFontAction->setShortcut(Qt::ControlModifier + Qt::Key_M); 85 connect(m_pMonospaceFontAction, SIGNAL(triggered()), this, SLOT(setFontMonospace())); 108 m_pMonospaceFontAction->setData((int)kFontType_Monospace); 109 connect(m_pMonospaceFontAction, SIGNAL(triggered()), this, SLOT(sltSelectFontType())); 86 110 87 111 /* Create action group for grouping of exclusive font menu items. */ … … 92 116 93 117 /* 94 * Color scheme. 95 * Create actions for color-scheme menu items. 96 */ 97 m_pGreenOnBlackAction = new QAction(tr("Green On Black"), this); 98 m_pGreenOnBlackAction->setCheckable(true); 99 m_pGreenOnBlackAction->setShortcut(Qt::ControlModifier + Qt::Key_1); 100 connect(m_pGreenOnBlackAction, SIGNAL(triggered()), this, SLOT(setColorGreenOnBlack())); 101 102 m_pBlackOnWhiteAction = new QAction(tr("Black On White"), this); 103 m_pBlackOnWhiteAction->setCheckable(true); 104 m_pBlackOnWhiteAction->setShortcut(Qt::ControlModifier + Qt::Key_2); 105 connect(m_pBlackOnWhiteAction, SIGNAL(triggered()), this, SLOT(setColorBlackOnWhite())); 106 107 /* Create action group for grouping of exclusive color-scheme menu items. */ 108 QActionGroup *pActionColorGroup = new QActionGroup(this); 109 pActionColorGroup->addAction(m_pGreenOnBlackAction); 110 pActionColorGroup->addAction(m_pBlackOnWhiteAction); 111 pActionColorGroup->setExclusive(true); 118 * Create actions for font size menu. 119 */ 120 uint32_t const uDefaultFontSize = font().pointSize(); 121 m_pActionFontSizeGroup = new QActionGroup(this); 122 for (uint32_t i = 0; i < RT_ELEMENTS(m_apFontSizeActions); i++) 123 { 124 char szTitle[32]; 125 RTStrPrintf(szTitle, sizeof(szTitle), s_uMinFontSize + i != uDefaultFontSize ? "%upt" : "%upt (default)", 126 s_uMinFontSize + i); 127 m_apFontSizeActions[i] = new QAction(tr(szTitle), this); 128 m_apFontSizeActions[i]->setCheckable(true); 129 m_apFontSizeActions[i]->setData(i + s_uMinFontSize); 130 connect(m_apFontSizeActions[i], SIGNAL(triggered()), this, SLOT(sltSelectFontSize())); 131 m_pActionFontSizeGroup->addAction(m_apFontSizeActions[i]); 132 } 112 133 113 134 /* 114 135 * Set the defaults (which syncs with the menu item checked state). 115 136 */ 116 117 if (m_pVirtualBox) 118 { 119 com::Bstr strColor; 120 HRESULT hrc = m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), strColor.asOutParam()); 121 if ( SUCCEEDED(hrc) 122 && strColor.compareUtf8("blackonwhite", com::Bstr::CaseInsensitive) == 0) 123 setColorBlackOnWhite(); 124 else 125 setColorGreenOnBlack(); 126 com::Bstr strFont; 127 hrc = m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/Font").raw(), strFont.asOutParam()); 128 if ( SUCCEEDED(hrc) 129 && strFont.compareUtf8("monospace", com::Bstr::CaseInsensitive) == 0) 130 setFontMonospace(); 131 else 132 setFontCourier(); 137 /* color scheme: */ 138 com::Bstr bstrColor; 139 HRESULT hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), bstrColor.asOutParam()) : E_FAIL; 140 if ( SUCCEEDED(hrc) 141 && bstrColor.compareUtf8("blackonwhite", com::Bstr::CaseInsensitive) == 0) 142 setColorScheme(kBlackOnWhite, false /*fSaveIt*/); 143 else 144 setColorScheme(kGreenOnBlack, false /*fSaveIt*/); 145 146 /* font: */ 147 com::Bstr bstrFont; 148 hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/Font").raw(), bstrFont.asOutParam()) : E_FAIL; 149 if ( SUCCEEDED(hrc) 150 && bstrFont.compareUtf8("monospace", com::Bstr::CaseInsensitive) == 0) 151 setFontType(kFontType_Monospace, false /*fSaveIt*/); 152 else 153 setFontType(kFontType_Courier, false /*fSaveIt*/); 154 155 /* font size: */ 156 com::Bstr bstrFontSize; 157 hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/FontSize").raw(), bstrFontSize.asOutParam()) : E_FAIL; 158 if (SUCCEEDED(hrc)) 159 { 160 com::Utf8Str strFontSize(bstrFontSize); 161 uint32_t uFontSizePrf = strFontSize.strip().toUInt32(); 162 if ( uFontSizePrf - s_uMinFontSize < (uint32_t)RT_ELEMENTS(m_apFontSizeActions) 163 && uFontSizePrf != uDefaultFontSize) 164 setFontSize(uFontSizePrf, false /*fSaveIt*/); 133 165 } 134 166 … … 155 187 */ 156 188 QMenu *pMenu = createStandardContextMenu(); 189 pMenu->addSeparator(); 190 157 191 QMenu *pColorMenu = pMenu->addMenu(tr("Co&lor Scheme")); 158 192 pColorMenu->addAction(m_pGreenOnBlackAction); … … 163 197 pFontMenu->addAction(m_pMonospaceFontAction); 164 198 199 QMenu *pFontSize = pMenu->addMenu(tr("Font &Size")); 200 for (unsigned i = 0; i < RT_ELEMENTS(m_apFontSizeActions); i++) 201 pFontSize->addAction(m_apFontSizeActions[i]); 202 165 203 pMenu->exec(pEvent->globalPos()); 166 204 delete pMenu; … … 169 207 170 208 void 171 VBoxDbgConsoleOutput::setColorGreenOnBlack() 172 { 173 setStyleSheet("QTextEdit { background-color: black; color: rgb(0, 224, 0) }"); 209 VBoxDbgConsoleOutput::setColorScheme(VBoxDbgConsoleColor enmScheme, bool fSaveIt) 210 { 211 const char *pszSetting; 212 QAction *pAction; 213 switch (enmScheme) 214 { 215 case kGreenOnBlack: 216 setStyleSheet("QTextEdit { background-color: black; color: rgb(0, 224, 0) }"); 217 pszSetting = "GreenOnBlack"; 218 pAction = m_pGreenOnBlackAction; 219 break; 220 case kBlackOnWhite: 221 setStyleSheet("QTextEdit { background-color: white; color: black }"); 222 pszSetting = "BlackOnWhite"; 223 pAction = m_pBlackOnWhiteAction; 224 break; 225 default: 226 AssertFailedReturnVoid(); 227 } 228 174 229 m_enmColorScheme = kGreenOnBlack; 175 230 176 /* This is used both as a trigger as well as called independently from code. 177 When used as a trigger, the checked is done automatically by Qt. */ 178 if (!m_pGreenOnBlackAction->isChecked()) 179 m_pGreenOnBlackAction->setChecked(true); 180 181 /* Make this setting persistent */ 182 if (m_pVirtualBox) 183 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), com::Bstr("GreenOnBlack").raw()); 184 } 185 186 187 void 188 VBoxDbgConsoleOutput::setColorBlackOnWhite() 189 { 190 setStyleSheet("QTextEdit { background-color: white; color: black }"); 191 m_enmColorScheme = kBlackOnWhite; 192 193 if (!m_pBlackOnWhiteAction->isChecked()) 194 m_pBlackOnWhiteAction->setChecked(true); 195 196 /* Make this setting persistent */ 197 if (m_pVirtualBox) 198 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), com::Bstr("BlackOnWhite").raw()); 199 } 200 201 202 void 203 VBoxDbgConsoleOutput::setFontCourier() 204 { 231 /* When going through a slot, the action is typically checked already by Qt. */ 232 if (!pAction->isChecked()) 233 pAction->setChecked(true); 234 235 /* Make this setting persistent. */ 236 if (m_pVirtualBox && fSaveIt) 237 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), com::Bstr(pszSetting).raw()); 238 } 239 240 241 void 242 VBoxDbgConsoleOutput::setFontType(VBoxDbgConsoleFontType enmFontType, bool fSaveIt) 243 { 244 QFont Font = font(); 245 QAction *pAction; 246 const char *pszSetting; 247 switch (enmFontType) 248 { 249 case kFontType_Courier: 205 250 #ifdef Q_WS_MAC 206 QFont Font("Monaco", 10, QFont::Normal, FALSE);207 Font.setStyleStrategy(QFont::NoAntialias);251 Font = QFont("Monaco", Font.pointSize(), QFont::Normal, FALSE); 252 Font.setStyleStrategy(QFont::NoAntialias); 208 253 #else 209 QFont Font = font(); 210 Font.setStyleHint(QFont::TypeWriter); 211 Font.setFamily("Courier [Monotype]"); 254 Font.setStyleHint(QFont::TypeWriter); 255 Font.setFamily("Courier [Monotype]"); 212 256 #endif 257 pszSetting = "Courier"; 258 pAction = m_pCourierFontAction; 259 break; 260 261 case kFontType_Monospace: 262 Font.setStyleHint(QFont::TypeWriter); 263 Font.setStyleStrategy(QFont::PreferAntialias); 264 Font.setFamily("Monospace [Monotype]"); 265 pszSetting = "Monospace"; 266 pAction = m_pMonospaceFontAction; 267 break; 268 269 default: 270 AssertFailedReturnVoid(); 271 } 272 213 273 setFont(Font); 214 274 215 if (!m_pCourierFontAction->isChecked()) 216 m_pCourierFontAction->setChecked(true); 217 218 /* Make this setting persistent */ 219 if (m_pVirtualBox) 220 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/Font").raw(), com::Bstr("Courier").raw()); 221 } 222 223 224 void 225 VBoxDbgConsoleOutput::setFontMonospace() 226 { 227 QFont Font = font(); 228 Font.setStyleHint(QFont::TypeWriter); 229 Font.setStyleStrategy(QFont::PreferAntialias); 230 Font.setFamily("Monospace [Monotype]"); 231 setFont(Font); 232 233 if (!m_pMonospaceFontAction->isChecked()) 234 m_pMonospaceFontAction->setChecked(true); 235 236 /* Make this setting persistent */ 237 if (m_pVirtualBox) 238 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/Font").raw(), com::Bstr("Monospace").raw()); 275 /* When going through a slot, the action is typically checked already by Qt. */ 276 if (!pAction->isChecked()) 277 pAction->setChecked(true); 278 279 /* Make this setting persistent. */ 280 if (m_pVirtualBox && fSaveIt) 281 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/Font").raw(), com::Bstr(pszSetting).raw()); 282 } 283 284 285 void 286 VBoxDbgConsoleOutput::setFontSize(uint32_t uFontSize, bool fSaveIt) 287 { 288 uint32_t idxAction = uFontSize - s_uMinFontSize; 289 if (idxAction < (uint32_t)RT_ELEMENTS(m_apFontSizeActions)) 290 { 291 if (!m_apFontSizeActions[idxAction]->isChecked()) 292 m_apFontSizeActions[idxAction]->setChecked(true); 293 294 QFont Font = font(); 295 Font.setPointSize(uFontSize); 296 setFont(Font); 297 298 /* Make this setting persistent if requested. */ 299 if (fSaveIt && m_pVirtualBox) 300 m_pVirtualBox->SetExtraData(com::Bstr("DbgConsole/FontSize").raw(), com::BstrFmt("%u", uFontSize).raw()); 301 } 302 } 303 304 305 void 306 VBoxDbgConsoleOutput::sltSelectColorScheme() 307 { 308 QAction *pAction = qobject_cast<QAction *>(sender()); 309 if (pAction) 310 setColorScheme((VBoxDbgConsoleColor)pAction->data().toInt(), true /*fSaveIt*/); 311 } 312 313 314 void 315 VBoxDbgConsoleOutput::sltSelectFontType() 316 { 317 QAction *pAction = qobject_cast<QAction *>(sender()); 318 if (pAction) 319 setFontType((VBoxDbgConsoleFontType)pAction->data().toInt(), true /*fSaveIt*/); 320 } 321 322 323 void 324 VBoxDbgConsoleOutput::sltSelectFontSize() 325 { 326 QAction *pAction = qobject_cast<QAction *>(sender()); 327 if (pAction) 328 setFontSize(pAction->data().toUInt(), true /*fSaveIt*/); 239 329 } 240 330
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器