- Timestamp:
- May 20, 2019 6:35:15 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78595 r78606 81 81 82 82 UISoftKeyboardKey(QWidget *pParent = 0); 83 void setAspectRatio(float fRatio); 83 void setWidth(int iWidth); 84 int width() const; 85 void updateFontSize(float multiplier); 84 86 85 87 protected: 86 88 87 virtual void resizeEvent(QResizeEvent *pEvent);88 89 89 private: 90 90 91 float m_fAspectRatio; 91 int m_iWidth; 92 int m_iDefaultPixelSize; 93 int m_iDefaultPointSize; 94 }; 95 96 /********************************************************************************************************************************* 97 * UISoftKeyboardRow definition. * 98 *********************************************************************************************************************************/ 99 100 class UISoftKeyboardRow : public QWidget 101 { 102 Q_OBJECT; 103 104 public: 105 106 UISoftKeyboardRow(QWidget *pParent = 0); 107 void updateLayout(); 108 int m_iWidth; 109 int m_iHeight; 110 QVector<UISoftKeyboardKey*> m_keys; 92 111 }; 93 112 … … 161 180 UISoftKeyboardKey::UISoftKeyboardKey(QWidget *pParent /* = 0 */) 162 181 :QPushButton(pParent) 163 , m_fAspectRatio(1.f) 164 { 165 } 166 167 void UISoftKeyboardKey::setAspectRatio(float fRatio) 168 { 169 m_fAspectRatio = fRatio; 170 } 171 172 void UISoftKeyboardKey::resizeEvent(QResizeEvent *pEvent) 173 { 174 // QWidget::resize(qMin(pEvent->size().width(),pEvent->size().height()), 175 // qMin(pEvent->size().width(),pEvent->size().height())); 176 177 QPushButton::resizeEvent(pEvent); 178 } 182 , m_iWidth(1) 183 { 184 m_iDefaultPointSize = font().pointSize(); 185 m_iDefaultPixelSize = font().pixelSize(); 186 } 187 188 void UISoftKeyboardKey::setWidth(int iWidth) 189 { 190 m_iWidth = iWidth; 191 } 192 193 int UISoftKeyboardKey::width() const 194 { 195 return m_iWidth; 196 } 197 198 void UISoftKeyboardKey::updateFontSize(float multiplier) 199 { 200 if (m_iDefaultPointSize != -1) 201 { 202 QFont newFont = font(); 203 newFont.setPointSize(multiplier * m_iDefaultPointSize); 204 setFont(newFont); 205 } 206 else 207 { 208 QFont newFont = font(); 209 newFont.setPixelSize(multiplier * m_iDefaultPixelSize); 210 setFont(newFont); 211 } 212 } 213 214 /********************************************************************************************************************************* 215 * UISoftKeyboardRow implementation. * 216 *********************************************************************************************************************************/ 217 218 UISoftKeyboardRow::UISoftKeyboardRow(QWidget *pParent /* = 0 */) 219 :QWidget(pParent) 220 , m_iWidth(0) 221 , m_iHeight(0) 222 223 { 224 } 225 226 void UISoftKeyboardRow::updateLayout() 227 { 228 if (m_iHeight == 0) 229 return; 230 231 float fMultiplier = height() / (float)m_iHeight; 232 int iX = 0; 233 for (int i = 0; i < m_keys.size(); ++i) 234 { 235 UISoftKeyboardKey *pKey = m_keys[i]; 236 if (!pKey) 237 continue; 238 pKey->setVisible(true); 239 pKey->updateFontSize(fMultiplier); 240 pKey->setGeometry(iX, 0, fMultiplier * pKey->width(), height()); 241 iX += fMultiplier * pKey->width(); 242 } 243 } 244 179 245 180 246 /********************************************************************************************************************************* … … 187 253 :QIWithRetranslateUI<QWidget>(pParent) 188 254 , m_pMainLayout(0) 189 , m_pContainer Layout(0)255 , m_pContainerWidget(0) 190 256 , m_pToolBar(0) 191 257 , m_fShowToolbar(fShowToolbar) 192 258 , m_strMachineName(strMachineName) 259 , m_iTotalRowHeight(0) 260 , m_iMaxRowWidth(0) 193 261 { 194 262 prepareObjects(); … … 212 280 { 213 281 QIWithRetranslateUI<QWidget>::resizeEvent(pEvent); 282 updateLayout(); 214 283 } 215 284 … … 222 291 if (!m_pMainLayout) 223 292 return; 224 QWidget *pContainerWidget = new QWidget; 225 if (!pContainerWidget) 226 return; 227 pContainerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 228 pContainerWidget->setStyleSheet("background-color:red;"); 229 230 m_pMainLayout->addWidget(pContainerWidget); 231 232 m_pContainerLayout = new QVBoxLayout; 233 m_pContainerLayout->setSpacing(0); 234 pContainerWidget->setLayout(m_pContainerLayout); 235 236 /* Configure layout: */ 237 293 m_pContainerWidget = new QWidget; 294 if (!m_pContainerWidget) 295 return; 296 m_pContainerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 297 //m_pContainerWidget->setStyleSheet("background-color:red;"); 298 //m_pContainerWidget->setAutoFillBackground(false); 299 300 m_pMainLayout->addWidget(m_pContainerWidget); 238 301 } 239 302 … … 256 319 void UISoftKeyboard::parseLayout() 257 320 { 258 if (!m_pContainerLayout)259 return;260 261 321 UIKeyboardLayoutReader reader; 262 322 SoftKeyboardLayout layout; … … 264 324 return; 265 325 326 m_iTotalRowHeight = 0; 327 m_iMaxRowWidth = 0; 328 qDeleteAll(m_rows); 329 m_rows.clear(); 330 266 331 for (int i = 0; i < layout.m_rows.size(); ++i) 267 332 { 268 QHBoxLayout *pRowLayout = new QHBoxLayout; 269 pRowLayout->setSpacing(0); 333 UISoftKeyboardRow *pNewRow = new UISoftKeyboardRow(m_pContainerWidget); 334 if ( i == 0) 335 pNewRow->setStyleSheet("background-color:yellow;"); 336 else 337 pNewRow->setStyleSheet("background-color:green;"); 338 339 m_rows.push_back(pNewRow); 340 pNewRow->m_iHeight = layout.m_rows[i].m_iHeight; 341 m_iTotalRowHeight += layout.m_rows[i].m_iHeight; 342 pNewRow->m_iWidth = 0; 270 343 for (int j = 0; j < layout.m_rows[i].m_keys.size(); ++j) 271 344 { 272 UISoftKeyboardKey *pKey = new UISoftKeyboardKey; 273 pRowLayout->addWidget(pKey); 274 //m_pContainerLayout->addWidget(pKey, i, j); 275 //pKey->setFixedSize(layout.m_rows[i].m_keys[j].m_iWidth, layout.m_rows[i].m_iHeight); 345 pNewRow->m_iWidth += layout.m_rows[i].m_keys[j].m_iWidth; 346 UISoftKeyboardKey *pKey = new UISoftKeyboardKey(pNewRow); 347 pNewRow->m_keys.append(pKey); 276 348 pKey->setText(layout.m_rows[i].m_keys[j].m_strLabel); 277 //if (j != 3) 278 279 280 // else 281 //m_pContainerLayout->setColumnStretch(j, 0); 282 //m_pContainerLayout->addSpacing(2); 283 // QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 284 // m_pContainerLayout->addItem(pSpacer); 349 pKey->setWidth(layout.m_rows[i].m_keys[j].m_iWidth); 350 pKey->hide(); 285 351 } 286 //pRowLayout->addStretch(1); 287 //m_pContainerLayout->setColumnStretch(layout.m_rows[i].m_keys.size()-1, 1); 288 m_pContainerLayout->addLayout(pRowLayout); 289 } 352 m_iMaxRowWidth = qMax(m_iMaxRowWidth, pNewRow->m_iWidth); 353 } 354 printf("total height %d %d\n", m_iTotalRowHeight, m_iMaxRowWidth); 355 356 357 // return; 358 // for (int i = 0; i < layout.m_rows.size(); ++i) 359 // { 360 // QHBoxLayout *pRowLayout = new QHBoxLayout; 361 // pRowLayout->setSpacing(0); 362 // for (int j = 0; j < layout.m_rows[i].m_keys.size(); ++j) 363 // { 364 // UISoftKeyboardKey *pKey = new UISoftKeyboardKey; 365 // pRowLayout->addWidget(pKey); 366 367 // //m_pContainerLayout->addWidget(pKey, i, j); 368 // //pKey->setFixedSize(layout.m_rows[i].m_keys[j].m_iWidth, layout.m_rows[i].m_iHeight); 369 // pKey->setText(layout.m_rows[i].m_keys[j].m_strLabel); 370 // //if (j != 3) 371 372 373 // // else 374 // //m_pContainerLayout->setColumnStretch(j, 0); 375 // //m_pContainerLayout->addSpacing(2); 376 // // QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 377 // // m_pContainerLayout->addItem(pSpacer); 378 // } 379 // //pRowLayout->addStretch(1); 380 // //m_pContainerLayout->setColumnStretch(layout.m_rows[i].m_keys.size()-1, 1); 381 // m_pContainerLayout->addLayout(pRowLayout); 382 // } 383 } 384 385 void UISoftKeyboard::updateLayout() 386 { 387 if (!m_pContainerWidget) 388 return; 389 390 QSize containerSize(m_pContainerWidget->size()); 391 if (containerSize.width() == 0 || containerSize.height() == 0) 392 return; 393 float fMultiplier = containerSize.width() / (float) m_iMaxRowWidth; 394 395 if (fMultiplier * m_iTotalRowHeight > containerSize.height()) 396 fMultiplier = containerSize.height() / (float) m_iTotalRowHeight; 397 398 int y = 0; 399 for (int i = 0; i < m_rows.size(); ++i) 400 { 401 UISoftKeyboardRow *pRow = m_rows[i]; 402 if (!pRow) 403 continue; 404 pRow->setGeometry(0, y, fMultiplier * pRow->m_iWidth, fMultiplier * pRow->m_iHeight); 405 pRow->setVisible(true); 406 y += fMultiplier * pRow->m_iHeight; 407 // pRow->setAutoFillBackground(true); 408 // pRow->raise(); 409 410 pRow->updateLayout(); 411 412 // m_pContainerWidget->lower(); 413 // pRow->update(); 414 415 } 416 update(); 417 /* Compute the size multiplier: */ 418 290 419 } 291 420 -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78595 r78606 36 36 /* Forward declarations: */ 37 37 class UISoftKeyboardKey; 38 class UISoftKeyboardRow; 38 39 class QHBoxLayout; 39 40 class QVBoxLayout; … … 66 67 void loadSettings(); 67 68 void parseLayout(); 69 void updateLayout(); 68 70 69 71 QHBoxLayout *m_pMainLayout; 70 Q VBoxLayout *m_pContainerLayout;72 QWidget *m_pContainerWidget; 71 73 UIToolBar *m_pToolBar; 72 74 const bool m_fShowToolbar; 73 75 QString m_strMachineName; 74 QVector<UISoftKeyboardKey*> m_keys; 76 QVector<UISoftKeyboardRow*> m_rows; 77 int m_iTotalRowHeight; 78 int m_iMaxRowWidth; 75 79 }; 76 80
Note:
See TracChangeset
for help on using the changeset viewer.