Changeset 78845 in vbox
- Timestamp:
- May 29, 2019 12:32:11 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 130950
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78812 r78845 36 36 #include "CEventSource.h" 37 37 38 class UISoftKeyboardWidget : public QWidget 39 { 40 Q_OBJECT; 41 public: 42 43 virtual QSize minimumSizeHint() const 44 { 45 return m_minimumSize; 46 } 47 48 virtual QSize sizeHint() const 49 { 50 return m_minimumSize; 51 } 52 53 void setNewMinimumSize(const QSize &size) 54 { 55 m_minimumSize = size; 56 updateGeometry(); 57 } 58 59 private: 60 61 QSize m_minimumSize; 62 }; 38 39 63 40 enum UIKeyState 64 41 { … … 79 56 }; 80 57 81 struct SoftKeyboardKey 82 { 83 /** Width and height might be inherited from the row and/or overwritten in row settings. */ 84 int m_iWidth; 85 int m_iHeight; 86 LONG m_strScanCode; 87 LONG m_strScanCodePrefix; 88 UIKeyType m_enmType; 89 QString m_strKeyCap; 90 int m_iSpaceWidthAfter; 58 59 class UISoftKeyboardRow 60 { 61 public: 62 /** Default width and height might be inherited from the layout and overwritten in row settings. */ 63 int m_iDefaultWidth; 64 int m_iDefaultHeight; 65 int m_iStartingSpace; 66 QVector<UISoftKeyboardKey> m_keys; 67 int m_iSpaceHeightAfter; 68 }; 69 70 71 /********************************************************************************************************************************* 72 * UISoftKeyboardKey definition. * 73 *********************************************************************************************************************************/ 74 75 class UISoftKeyboardKey 76 { 77 78 public: 79 80 UISoftKeyboardKey(); 81 82 const QRect keyGeometry() const; 83 void setKeyGeometry(const QRect &rect); 84 85 const QString &keyCap() const; 86 void setKeyCap(const QString &strKeyCap); 87 88 void setWidth(int iWidth); 89 int width() const; 90 91 void setHeight(int iHeight); 92 int height() const; 93 94 void setScanCode(LONG scanCode); 95 LONG scanCode() const; 96 97 void setScanCodePrefix(LONG scanCode); 98 LONG scanCodePrefix() const; 99 100 void setSpaceWidthAfter(int iSpace); 101 int spaceWidthAfter() const; 102 103 void setType(UIKeyType enmType); 104 UIKeyType type() const; 105 106 UIKeyState state() const; 107 QVector<LONG> scanCodeWithPrefix() const; 108 109 void release(); 110 111 void setPolygon(const QPolygon &polygon); 112 const QPolygon &polygon() const; 113 114 QPolygon polygonInGlobal() const; 115 116 int m_iDefaultPixelSize; 117 int m_iDefaultPointSize; 118 LONG m_scanCode; 119 LONG m_scanCodePrefix; 120 91 121 int m_iCutoutWidth; 92 122 int m_iCutoutHeight; 93 123 /** -1 is no cutout. 0 is the topleft corner. we go clockwise. */ 94 124 int m_iCutoutCorner; 95 }; 96 97 struct SoftKeyboardRow 98 { 99 /** Default width and height might be inherited from the layout and overwritten in row settings. */ 100 int m_iDefaultWidth; 101 int m_iDefaultHeight; 102 int m_iStartingSpace; 103 QList<SoftKeyboardKey> m_keys; 104 }; 105 106 struct SoftKeyboardLayout 107 { 108 int m_iDefaultWidth; 109 int m_iDefaultHeight; 110 QList<SoftKeyboardRow> m_rows; 111 }; 112 113 114 /********************************************************************************************************************************* 115 * UISoftKeyboardKey definition. * 116 *********************************************************************************************************************************/ 117 118 class UISoftKeyboardKey : public QToolButton 119 { 120 Q_OBJECT; 121 122 signals: 123 124 void sigStateChanged(); 125 126 public: 127 128 UISoftKeyboardKey(QWidget *pParent = 0); 129 130 void setWidth(int iWidth); 131 int width() const; 132 133 void setScanCode(LONG scanCode); 134 LONG scanCode() const; 135 136 void setScanCodePrefix(LONG scanCode); 137 LONG scanCodePrefix() const; 138 139 void setSpaceAfter(int iSpace); 140 int spaceAfter() const; 141 142 void setType(UIKeyType enmType); 143 UIKeyType type() const; 144 145 void setScaleMultiplier(float fMultiplier); 146 147 UIKeyState state() const; 148 QVector<LONG> scanCodeWithPrefix() const; 149 void updateFontSize(); 150 151 void release(); 152 void setVertices(const QVector<QPoint> &vertices); 125 153 126 154 127 protected: 155 128 156 virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;129 //virtual void mousePressEvent(QMouseEvent *pEvent) /* override */; 157 130 virtual void paintEvent(QPaintEvent *pPaintEvent) /* override */; 158 131 … … 160 133 161 134 void updateState(bool fPressed); 162 void updateBackground(); 163 164 int m_iWidth; 165 int m_iDefaultPixelSize; 166 int m_iDefaultPointSize; 167 int m_iSpaceAfter; 168 LONG m_scanCode; 169 LONG m_scanCodePrefix; 170 UIKeyType m_enmType; 135 136 QRect m_keyGeometry; 137 QString m_strKeyCap; 138 /** Stores the key polygon in local coordinates. */ 139 QPolygon m_polygon; 140 141 UIKeyType m_enmType; 171 142 UIKeyState m_enmState; 172 QPalette m_defaultPalette; 173 float m_fScaleMultiplier; 174 QVector<QPoint> m_vertices; 143 144 /** Key width as it is read from the xml file. */ 145 int m_iWidth; 146 /** Key height as it is read from the xml file. */ 147 int m_iHeight; 148 int m_iSpaceWidthAfter; 175 149 }; 176 150 … … 184 158 public: 185 159 186 bool parseXMLFile(const QString &strFileName, SoftKeyboardLayout &layout);187 static QVector<QPoint> computeKeyVertices(const SoftKeyboardKey &key);160 bool parseXMLFile(const QString &strFileName, QVector<UISoftKeyboardRow> &rows); 161 static QVector<QPoint> computeKeyVertices(const UISoftKeyboardKey &key); 188 162 private: 189 163 190 void parseKey(SoftKeyboardRow &row); 191 void parseRow(SoftKeyboardLayout &layout); 192 void parseSpace(SoftKeyboardRow &row); 193 void parseCutout(SoftKeyboardKey &key); 164 void parseKey(UISoftKeyboardRow &row); 165 void parseRow(int iDefaultWidth, int iDefaultHeight, QVector<UISoftKeyboardRow> &rows); 166 /** Parses the verticel space between the rows. */ 167 void parseRowSpace(QVector<UISoftKeyboardRow> &rows); 168 /** Parses the horizontal space between keys. */ 169 void parseKeySpace(UISoftKeyboardRow &row); 170 void parseCutout(UISoftKeyboardKey &key); 194 171 195 172 QXmlStreamReader m_xmlReader; … … 200 177 *********************************************************************************************************************************/ 201 178 202 bool UIKeyboardLayoutReader::parseXMLFile(const QString &strFileName, SoftKeyboardLayout &layout)179 bool UIKeyboardLayoutReader::parseXMLFile(const QString &strFileName, QVector<UISoftKeyboardRow> &rows) 203 180 { 204 181 QFile xmlFile(strFileName); … … 215 192 216 193 QXmlStreamAttributes attributes = m_xmlReader.attributes(); 217 layout.m_iDefaultWidth = attributes.value("defaultWidth").toInt();218 layout.m_iDefaultHeight = attributes.value("defaultHeight").toInt();194 int iDefaultWidth = attributes.value("defaultWidth").toInt(); 195 int iDefaultHeight = attributes.value("defaultHeight").toInt(); 219 196 220 197 while (m_xmlReader.readNextStartElement()) 221 198 { 222 199 if (m_xmlReader.name() == "row") 223 {224 parseRow(layout);225 }200 parseRow(iDefaultWidth, iDefaultHeight, rows); 201 else if (m_xmlReader.name() == "space") 202 parseRowSpace(rows); 226 203 else 227 204 m_xmlReader.skipCurrentElement(); … … 231 208 } 232 209 233 void UIKeyboardLayoutReader::parseRow(SoftKeyboardLayout &layout) 234 { 235 SoftKeyboardRow row; 236 237 row.m_iDefaultWidth = layout.m_iDefaultWidth; 238 row.m_iDefaultHeight = layout.m_iDefaultHeight; 210 void UIKeyboardLayoutReader::parseRow(int iDefaultWidth, int iDefaultHeight, QVector<UISoftKeyboardRow> &rows) 211 { 212 rows.append(UISoftKeyboardRow()); 213 UISoftKeyboardRow &row = rows.back(); 214 215 row.m_iDefaultWidth = iDefaultWidth; 216 row.m_iDefaultHeight = iDefaultHeight; 217 row.m_iSpaceHeightAfter = 0; 239 218 240 219 /* Override the layout attributes if the row also has them: */ … … 249 228 parseKey(row); 250 229 else if (m_xmlReader.name() == "space") 251 parse Space(row);230 parseKeySpace(row); 252 231 else 253 232 m_xmlReader.skipCurrentElement(); 254 233 } 255 layout.m_rows.append(row); 256 } 257 258 void UIKeyboardLayoutReader::parseKey(SoftKeyboardRow &row) 259 { 260 SoftKeyboardKey key; 261 key.m_iWidth = row.m_iDefaultWidth; 262 key.m_iHeight = row.m_iDefaultHeight; 263 key.m_iSpaceWidthAfter = 0; 234 } 235 236 void UIKeyboardLayoutReader::parseRowSpace(QVector<UISoftKeyboardRow> &rows) 237 { 238 int iSpace = 0; 239 while (m_xmlReader.readNextStartElement()) 240 { 241 if (m_xmlReader.name() == "height") 242 iSpace = m_xmlReader.readElementText().toInt(); 243 else 244 m_xmlReader.skipCurrentElement(); 245 } 246 if (!rows.empty()) 247 rows.back().m_iSpaceHeightAfter = iSpace; 248 } 249 250 void UIKeyboardLayoutReader::parseKey(UISoftKeyboardRow &row) 251 { 252 row.m_keys.append(UISoftKeyboardKey()); 253 UISoftKeyboardKey &key = row.m_keys.back(); 254 key.setWidth(row.m_iDefaultWidth); 255 key.setHeight(row.m_iDefaultHeight); 264 256 key.m_iCutoutCorner = -1; 265 257 while (m_xmlReader.readNextStartElement()) 266 258 { 267 259 if (m_xmlReader.name() == "width") 268 key. m_iWidth = m_xmlReader.readElementText().toInt();260 key.setWidth(m_xmlReader.readElementText().toInt()); 269 261 else if (m_xmlReader.name() == "height") 270 key. m_iHeight = m_xmlReader.readElementText().toInt();262 key.setHeight(m_xmlReader.readElementText().toInt()); 271 263 else if (m_xmlReader.name() == "scancode") 272 264 { 273 265 QString strCode = m_xmlReader.readElementText(); 274 266 bool fOk = false; 275 key.m_s trScanCode = strCode.toInt(&fOk, 16);267 key.m_scanCode = strCode.toInt(&fOk, 16); 276 268 } 277 269 else if (m_xmlReader.name() == "scancodeprefix") … … 279 271 QString strCode = m_xmlReader.readElementText(); 280 272 bool fOk = false; 281 key.m_s trScanCodePrefix = strCode.toInt(&fOk, 16);273 key.m_scanCodePrefix = strCode.toInt(&fOk, 16); 282 274 } 283 275 else if (m_xmlReader.name() == "keycap") 284 { 285 if (key.m_strKeyCap.isEmpty()) 286 key.m_strKeyCap = m_xmlReader.readElementText(); 287 else 288 key.m_strKeyCap += "\n" + m_xmlReader.readElementText(); 289 } 276 key.setKeyCap(m_xmlReader.readElementText()); 290 277 else if (m_xmlReader.name() == "cutout") 291 278 parseCutout(key); 292 293 294 279 // else if (m_xmlReader.name() == "type") 295 280 // { … … 303 288 m_xmlReader.skipCurrentElement(); 304 289 } 305 row.m_keys.append(key); 306 } 307 308 void UIKeyboardLayoutReader::parseSpace(SoftKeyboardRow &row) 290 } 291 292 void UIKeyboardLayoutReader::parseKeySpace(UISoftKeyboardRow &row) 309 293 { 310 294 int iWidth = row.m_iDefaultWidth; … … 318 302 if (row.m_keys.size() <= 0) 319 303 return; 320 row.m_keys.back(). m_iSpaceWidthAfter = iWidth;321 } 322 323 void UIKeyboardLayoutReader::parseCutout( SoftKeyboardKey &key)304 row.m_keys.back().setSpaceWidthAfter(iWidth); 305 } 306 307 void UIKeyboardLayoutReader::parseCutout(UISoftKeyboardKey &key) 324 308 { 325 309 while (m_xmlReader.readNextStartElement()) … … 346 330 } 347 331 348 QVector<QPoint> UIKeyboardLayoutReader::computeKeyVertices(const SoftKeyboardKey &key)332 QVector<QPoint> UIKeyboardLayoutReader::computeKeyVertices(const UISoftKeyboardKey &key) 349 333 { 350 334 QVector<QPoint> vertices; 351 335 352 if (key.m_iCutoutCorner == -1 || key. m_iWidth <= key.m_iCutoutWidth || key.m_iHeight<= key.m_iCutoutHeight)336 if (key.m_iCutoutCorner == -1 || key.width() <= key.m_iCutoutWidth || key.height() <= key.m_iCutoutHeight) 353 337 { 354 338 vertices.append(QPoint(0, 0)); 355 vertices.append(QPoint(key. m_iWidth, 0));356 vertices.append(QPoint(key. m_iWidth, key.m_iHeight));357 vertices.append(QPoint(0, key. m_iHeight));339 vertices.append(QPoint(key.width(), 0)); 340 vertices.append(QPoint(key.width(), key.height())); 341 vertices.append(QPoint(0, key.height())); 358 342 return vertices; 359 343 } … … 361 345 { 362 346 vertices.append(QPoint(key.m_iCutoutWidth, 0)); 363 vertices.append(QPoint(key. m_iWidth, 0));364 vertices.append(QPoint(key. m_iWidth, key.m_iHeight));365 vertices.append(QPoint(0, key. m_iHeight));347 vertices.append(QPoint(key.width(), 0)); 348 vertices.append(QPoint(key.width(), key.height())); 349 vertices.append(QPoint(0, key.height())); 366 350 vertices.append(QPoint(0, key.m_iCutoutHeight)); 367 351 vertices.append(QPoint(key.m_iCutoutWidth, key.m_iCutoutHeight)); … … 370 354 { 371 355 vertices.append(QPoint(0, 0)); 372 vertices.append(QPoint(key. m_iWidth- key.m_iCutoutWidth, 0));373 vertices.append(QPoint(key. m_iWidth- key.m_iCutoutWidth, key.m_iCutoutHeight));374 vertices.append(QPoint(key. m_iWidth, key.m_iCutoutHeight));375 vertices.append(QPoint(key. m_iWidth, key.m_iHeight));376 vertices.append(QPoint(0, key. m_iHeight));356 vertices.append(QPoint(key.width() - key.m_iCutoutWidth, 0)); 357 vertices.append(QPoint(key.width() - key.m_iCutoutWidth, key.m_iCutoutHeight)); 358 vertices.append(QPoint(key.width(), key.m_iCutoutHeight)); 359 vertices.append(QPoint(key.width(), key.height())); 360 vertices.append(QPoint(0, key.height())); 377 361 } 378 362 else if (key.m_iCutoutCorner == 2) 379 363 { 380 364 vertices.append(QPoint(0, 0)); 381 vertices.append(QPoint(key. m_iWidth, 0));382 vertices.append(QPoint(key. m_iWidth, key.m_iCutoutHeight));383 vertices.append(QPoint(key. m_iWidth- key.m_iCutoutWidth, key.m_iCutoutHeight));384 vertices.append(QPoint(key. m_iWidth - key.m_iCutoutWidth, key.m_iHeight));385 vertices.append(QPoint(0, key. m_iHeight));365 vertices.append(QPoint(key.width(), 0)); 366 vertices.append(QPoint(key.width(), key.m_iCutoutHeight)); 367 vertices.append(QPoint(key.width() - key.m_iCutoutWidth, key.m_iCutoutHeight)); 368 vertices.append(QPoint(key.width() - key.m_iCutoutWidth, key.height())); 369 vertices.append(QPoint(0, key.height())); 386 370 } 387 371 else if (key.m_iCutoutCorner == 3) 388 372 { 389 373 vertices.append(QPoint(0, 0)); 390 vertices.append(QPoint(key. m_iWidth, 0));391 vertices.append(QPoint(key. m_iWidth, key.m_iHeight));392 vertices.append(QPoint(key.m_iCutoutWidth, key. m_iHeight));393 vertices.append(QPoint(key.m_iCutoutWidth, key. m_iHeight- key.m_iCutoutHeight));394 vertices.append(QPoint(0, key. m_iHeight- key.m_iCutoutHeight));374 vertices.append(QPoint(key.width(), 0)); 375 vertices.append(QPoint(key.width(), key.height())); 376 vertices.append(QPoint(key.m_iCutoutWidth, key.height())); 377 vertices.append(QPoint(key.m_iCutoutWidth, key.height() - key.m_iCutoutHeight)); 378 vertices.append(QPoint(0, key.height() - key.m_iCutoutHeight)); 395 379 } 396 380 return vertices; 397 381 } 382 383 class UISoftKeyboardWidget : public QWidget 384 { 385 Q_OBJECT; 386 public: 387 388 virtual QSize minimumSizeHint() const 389 { 390 return m_minimumSize; 391 } 392 393 virtual QSize sizeHint() const 394 { 395 return m_minimumSize; 396 } 397 398 void setNewMinimumSize(const QSize &size) 399 { 400 m_minimumSize = size; 401 updateGeometry(); 402 } 403 QVector<UISoftKeyboardRow> m_rows; 404 405 void setInitialSize(int iWidth, int iHeight) 406 { 407 m_iInitialWidth = iWidth; 408 m_iInitialHeight = iHeight; 409 } 410 411 protected: 412 413 void paintEvent(QPaintEvent *pEvent) /* override */ 414 { 415 Q_UNUSED(pEvent); 416 if (m_iInitialWidth == 0 || m_iInitialHeight == 0) 417 return; 418 419 m_fMultiplierX = width() / (float) m_iInitialWidth; 420 m_fMultiplierY = height() / (float) m_iInitialHeight; 421 422 QPainter painter(this); 423 QFont painterFont(font()); 424 painterFont.setPixelSize(16); 425 painter.setFont(painterFont); 426 painter.setRenderHint(QPainter::Antialiasing); 427 painter.setPen(QPen(QColor(0, 0,0), 2)); 428 painter.setBrush(QBrush(QColor(255, 0,0))); 429 painter.scale(m_fMultiplierX, m_fMultiplierY); 430 for (int i = 0; i < m_rows.size(); ++i) 431 { 432 QVector<UISoftKeyboardKey> &keys = m_rows[i].m_keys; 433 for (int j = 0; j < keys.size(); ++j) 434 { 435 UISoftKeyboardKey &key = keys[j]; 436 painter.translate(key.keyGeometry().x(), key.keyGeometry().y()); 437 painter.drawPolygon(key.polygon()); 438 QRect textRect(0, 0, key.keyGeometry().width(), key.keyGeometry().height()); 439 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 440 painter.translate(-key.keyGeometry().x(), -key.keyGeometry().y()); 441 } 442 } 443 } 444 445 void mousePressEvent(QMouseEvent *pEvent) 446 { 447 QPoint eventPosition(pEvent->pos().x() / m_fMultiplierX, pEvent->pos().y() / m_fMultiplierY); 448 QWidget::mousePressEvent(pEvent); 449 for (int i = 0; i < m_rows.size(); ++i) 450 { 451 QVector<UISoftKeyboardKey> &keys = m_rows[i].m_keys; 452 for (int j = 0; j < keys.size(); ++j) 453 { 454 UISoftKeyboardKey &key = keys[j]; 455 if (key.polygonInGlobal().containsPoint(eventPosition, Qt::OddEvenFill)) 456 { 457 //printf ("%s\n", qPrintable(key.keyCap())); 458 break; 459 } 460 } 461 } 462 } 463 464 private: 465 466 QSize m_minimumSize; 467 int m_iInitialHeight; 468 int m_iInitialWidth; 469 float m_fMultiplierX; 470 float m_fMultiplierY; 471 472 }; 398 473 399 474 … … 402 477 *********************************************************************************************************************************/ 403 478 404 UISoftKeyboardKey::UISoftKeyboardKey(QWidget *pParent /* = 0 */) 405 :QToolButton(pParent) 406 , m_iWidth(1) 407 , m_iSpaceAfter(0) 408 , m_scanCode(0) 479 UISoftKeyboardKey::UISoftKeyboardKey() 480 : m_scanCode(0) 409 481 , m_scanCodePrefix(0) 410 482 , m_enmType(UIKeyType_Ordinary) 411 483 , m_enmState(UIKeyState_NotPressed) 412 , m_fScaleMultiplier(1.f) 413 { 414 m_iDefaultPointSize = font().pointSize(); 415 m_iDefaultPixelSize = font().pixelSize(); 416 m_defaultPalette = palette(); 484 , m_iWidth(0) 485 , m_iHeight(0) 486 , m_iSpaceWidthAfter(0) 487 { 488 } 489 490 const QRect UISoftKeyboardKey::keyGeometry() const 491 { 492 return m_keyGeometry; 493 } 494 495 void UISoftKeyboardKey::setKeyGeometry(const QRect &rect) 496 { 497 m_keyGeometry = rect; 498 } 499 500 const QString &UISoftKeyboardKey::keyCap() const 501 { 502 return m_strKeyCap; 503 } 504 505 void UISoftKeyboardKey::setKeyCap(const QString &strKeyCap) 506 { 507 if (m_strKeyCap.isEmpty()) 508 m_strKeyCap = strKeyCap; 509 else 510 m_strKeyCap += "\n" + strKeyCap; 417 511 } 418 512 … … 427 521 } 428 522 523 void UISoftKeyboardKey::setHeight(int iHeight) 524 { 525 m_iHeight = iHeight; 526 } 527 528 int UISoftKeyboardKey::height() const 529 { 530 return m_iHeight; 531 } 532 429 533 void UISoftKeyboardKey::setScanCode(LONG scanCode) 430 534 { … … 447 551 } 448 552 449 void UISoftKeyboardKey::setSpace After(int iSpace)450 { 451 m_iSpace After = iSpace;452 } 453 454 int UISoftKeyboardKey::space After() const455 { 456 return m_iSpace After;553 void UISoftKeyboardKey::setSpaceWidthAfter(int iSpace) 554 { 555 m_iSpaceWidthAfter = iSpace; 556 } 557 558 int UISoftKeyboardKey::spaceWidthAfter() const 559 { 560 return m_iSpaceWidthAfter; 457 561 } 458 562 … … 467 571 } 468 572 469 void UISoftKeyboardKey::setScaleMultiplier(float fMultiplier)470 {471 m_fScaleMultiplier = fMultiplier;472 }473 474 573 UIKeyState UISoftKeyboardKey::state() const 475 574 { … … 477 576 } 478 577 479 void UISoftKeyboardKey::updateFontSize()480 {481 QFont newFont = font();482 if (m_iDefaultPointSize != -1)483 newFont.setPointSize(m_fScaleMultiplier * m_iDefaultPointSize);484 else485 newFont.setPixelSize(m_fScaleMultiplier * m_iDefaultPixelSize);486 setFont(newFont);487 }488 489 578 void UISoftKeyboardKey::release() 490 579 { … … 492 581 } 493 582 494 void UISoftKeyboardKey::setVertices(const QVector<QPoint> &vertices) 495 { 496 m_vertices = vertices; 497 } 498 499 void UISoftKeyboardKey::mousePressEvent(QMouseEvent *pEvent) 500 { 501 QToolButton::mousePressEvent(pEvent); 502 updateState(true); 583 void UISoftKeyboardKey::setPolygon(const QPolygon &polygon) 584 { 585 m_polygon = polygon; 586 } 587 588 const QPolygon &UISoftKeyboardKey::polygon() const 589 { 590 return m_polygon; 591 } 592 593 QPolygon UISoftKeyboardKey::polygonInGlobal() const 594 { 595 QPolygon globalPolygon(m_polygon); 596 globalPolygon.translate(m_keyGeometry.x(), m_keyGeometry.y()); 597 return globalPolygon; 503 598 } 504 599 … … 508 603 // QToolButton::paintEvent(pEvent); 509 604 // return; 510 QPainter painter(this);511 QFont painterFont(font());512 painterFont.setPixelSize(16);513 painter.setFont(painterFont);514 515 painter.setRenderHint(QPainter::Antialiasing);516 painter.setPen(QPen(QColor(0, 0,0), 2));517 painter.setBrush(QBrush(QColor(255, 0,0)));518 painter.drawPolygon(&(m_vertices[0]), m_vertices.size());519 QRect textRect(0, 0, width(), height());520 painter.drawText(textRect, Qt::TextWordWrap, text());521 605 } 522 606 … … 552 636 } 553 637 } 554 emit sigStateChanged(); 555 updateBackground(); 556 } 557 558 void UISoftKeyboardKey::updateBackground() 559 { 560 if (m_enmState == UIKeyState_NotPressed) 561 { 562 setPalette(m_defaultPalette); 563 return; 564 } 565 QColor newColor; 566 567 if (m_enmState == UIKeyState_Pressed) 568 newColor = QColor(20, 255, 42); 569 else 570 newColor = QColor(255, 7, 58); 571 572 setAutoFillBackground(true); 573 QPalette currentPalette = palette(); 574 currentPalette.setColor(QPalette::Button, newColor); 575 576 setPalette(currentPalette); 577 update(); 578 } 638 } 579 639 580 640 /********************************************************************************************************************************* … … 589 649 , m_pContainerWidget(0) 590 650 , m_strMachineName(strMachineName) 591 , m_iTotalRowHeight(0) 592 , m_iMaxRowWidth(0) 651 593 652 , m_fKeepAspectRatio(false) 594 653 , m_iXSpacing(5) 595 654 , m_iYSpacing(5) 596 , m_iLeftMargin( 5)597 , m_iTopMargin( 5)598 , m_iRightMargin( 5)599 , m_iBottomMargin( 5)655 , m_iLeftMargin(10) 656 , m_iTopMargin(10) 657 , m_iRightMargin(10) 658 , m_iBottomMargin(10) 600 659 { 601 660 setAttribute(Qt::WA_DeleteOnClose); … … 617 676 } 618 677 619 void UISoftKeyboard::resizeEvent(QResizeEvent *pEvent)620 {621 QIWithRetranslateUI<QMainWindow>::resizeEvent(pEvent);622 //updateLayout();623 }624 625 678 void UISoftKeyboard::sltHandleKeyPress() 626 679 { 627 UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());628 if (!pKey)629 return;630 if (pKey->type() == UIKeyType_Modifier)631 return;632 633 QVector<LONG> sequence;634 635 /* Add the pressed modifiers first: */636 for (int i = 0; i < m_pressedModifiers.size(); ++i)637 {638 UISoftKeyboardKey *pModifier = m_pressedModifiers[i];639 if (pModifier->scanCodePrefix() != 0)640 sequence << pModifier->scanCodePrefix();641 sequence << pModifier->scanCode();642 }643 644 if (pKey->scanCodePrefix() != 0)645 sequence << pKey->scanCodePrefix();646 sequence << pKey->scanCode();647 keyboard().PutScancodes(sequence);680 // UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender()); 681 // if (!pKey) 682 // return; 683 // if (pKey->type() == UIKeyType_Modifier) 684 // return; 685 686 // QVector<LONG> sequence; 687 688 // /* Add the pressed modifiers first: */ 689 // for (int i = 0; i < m_pressedModifiers.size(); ++i) 690 // { 691 // UISoftKeyboardKey *pModifier = m_pressedModifiers[i]; 692 // if (pModifier->scanCodePrefix() != 0) 693 // sequence << pModifier->scanCodePrefix(); 694 // sequence << pModifier->scanCode(); 695 // } 696 697 // if (pKey->scanCodePrefix() != 0) 698 // sequence << pKey->scanCodePrefix(); 699 // sequence << pKey->scanCode(); 700 // keyboard().PutScancodes(sequence); 648 701 } 649 702 650 703 void UISoftKeyboard::sltHandleKeyRelease() 651 704 { 652 UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());653 if (!pKey)654 return;655 /* We only send the scan codes of Ordinary keys: */656 if (pKey->type() == UIKeyType_Modifier)657 return;658 659 QVector<LONG> sequence;660 if (pKey->scanCodePrefix() != 0)661 sequence << pKey->scanCodePrefix();662 sequence << (pKey->scanCode() | 0x80);663 664 /* Add the pressed modifiers in the reverse order: */665 for (int i = m_pressedModifiers.size() - 1; i >= 0; --i)666 {667 UISoftKeyboardKey *pModifier = m_pressedModifiers[i];668 if (pModifier->scanCodePrefix() != 0)669 sequence << pModifier->scanCodePrefix();670 sequence << (pModifier->scanCode() | 0x80);671 /* Release the pressed modifiers (if there are not locked): */672 pModifier->release();673 }674 keyboard().PutScancodes(sequence);705 //UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender()); 706 // if (!pKey) 707 // return; 708 // /* We only send the scan codes of Ordinary keys: */ 709 // if (pKey->type() == UIKeyType_Modifier) 710 // return; 711 712 // QVector<LONG> sequence; 713 // if (pKey->scanCodePrefix() != 0) 714 // sequence << pKey->scanCodePrefix(); 715 // sequence << (pKey->scanCode() | 0x80); 716 717 // /* Add the pressed modifiers in the reverse order: */ 718 // for (int i = m_pressedModifiers.size() - 1; i >= 0; --i) 719 // { 720 // UISoftKeyboardKey *pModifier = m_pressedModifiers[i]; 721 // if (pModifier->scanCodePrefix() != 0) 722 // sequence << pModifier->scanCodePrefix(); 723 // sequence << (pModifier->scanCode() | 0x80); 724 // /* Release the pressed modifiers (if there are not locked): */ 725 // pModifier->release(); 726 // } 727 // keyboard().PutScancodes(sequence); 675 728 } 676 729 677 730 void UISoftKeyboard::sltHandleModifierStateChange() 678 731 { 679 UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());680 if (!pKey)681 return;682 if (pKey->type() != UIKeyType_Modifier)683 return;684 if (pKey->state() == UIKeyState_NotPressed)685 {686 m_pressedModifiers.removeOne(pKey);687 }688 else689 {690 if (!m_pressedModifiers.contains(pKey))691 m_pressedModifiers.append(pKey);692 }732 // UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender()); 733 // if (!pKey) 734 // return; 735 // if (pKey->type() != UIKeyType_Modifier) 736 // return; 737 // if (pKey->state() == UIKeyState_NotPressed) 738 // { 739 // m_pressedModifiers.removeOne(pKey); 740 // } 741 // else 742 // { 743 // if (!m_pressedModifiers.contains(pKey)) 744 // m_pressedModifiers.append(pKey); 745 // } 693 746 } 694 747 695 748 void UISoftKeyboard::prepareObjects() 696 749 { 697 698 /* Create layout: */699 // m_pMainLayout = new QHBoxLayout(this);700 // if (!m_pMainLayout)701 // return;702 750 m_pContainerWidget = new UISoftKeyboardWidget; 703 751 if (!m_pContainerWidget) 704 752 return; 705 753 m_pContainerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 706 707 m_pContainerWidget->setStyleSheet("background-color:red;");708 //m_pMainLayout->addWidget(m_pContainerWidget);709 754 setCentralWidget(m_pContainerWidget); 710 711 755 m_pContainerWidget->updateGeometry(); 712 756 } … … 730 774 void UISoftKeyboard::parseLayout() 731 775 { 776 if (!m_pContainerWidget) 777 return; 732 778 UIKeyboardLayoutReader reader; 733 SoftKeyboardLayout layout; 734 layout.m_iDefaultWidth = 0; 735 layout.m_iDefaultHeight = 0; 736 if (!reader.parseXMLFile(":/102_iso.xml", layout)) 779 QVector<UISoftKeyboardRow> &rows = m_pContainerWidget->m_rows; 780 if (!reader.parseXMLFile(":/102_iso.xml", rows)) 737 781 return; 738 782 int iY = m_iTopMargin; 739 783 int iMaxWidth = 0; 740 for (int i = 0; i < layout.m_rows.size(); ++i) 741 { 742 m_keys.append(QVector<UISoftKeyboardKey*>()); 743 const SoftKeyboardRow &row = layout.m_rows[i]; 784 for (int i = 0; i < rows.size(); ++i) 785 { 786 UISoftKeyboardRow &row = rows[i]; 744 787 int iX = m_iLeftMargin; 745 QVector<UISoftKeyboardKey*> &rowKeyVector = m_keys.back();746 788 int iRowHeight = row.m_iDefaultHeight; 747 789 for (int j = 0; j < row.m_keys.size(); ++j) 748 790 { 749 const SoftKeyboardKey &key = row.m_keys[j]; 750 UISoftKeyboardKey *pKey = new UISoftKeyboardKey(m_pContainerWidget); 751 rowKeyVector.append(pKey); 752 pKey->setText(key.m_strKeyCap); 753 pKey->setGeometry(iX, iY, key.m_iWidth, key.m_iHeight); 754 pKey->setWidth(key.m_iWidth); 755 // printf("key.m_iWidth %d\n", pKey->width()); 756 pKey->setVertices(UIKeyboardLayoutReader::computeKeyVertices(key)); 757 iX += key.m_iWidth; 791 UISoftKeyboardKey &key = row.m_keys[j]; 792 key.setKeyGeometry(QRect(iX, iY, key.width(), key.height())); 793 key.setPolygon(QPolygon(UIKeyboardLayoutReader::computeKeyVertices(key))); 794 iX += key.width(); 758 795 if (j < row.m_keys.size() - 1) 759 796 iX += m_iXSpacing; 760 if (key.m_iSpaceWidthAfter != 0) 761 iX += (m_iXSpacing + key.m_iSpaceWidthAfter); 762 iRowHeight = qMax(iRowHeight, key.m_iHeight); 797 if (key.spaceWidthAfter() != 0) 798 iX += (m_iXSpacing + key.spaceWidthAfter()); 763 799 } 800 if (row.m_iSpaceHeightAfter != 0) 801 iY += row.m_iSpaceHeightAfter + m_iYSpacing; 764 802 iMaxWidth = qMax(iMaxWidth, iX); 765 803 iY += iRowHeight; 766 if (i < layout.m_rows.size() - 1)804 if (i < rows.size() - 1) 767 805 iY += m_iYSpacing; 768 806 } 769 m_pContainerWidget->setNewMinimumSize(QSize(iMaxWidth + m_iRightMargin, iY + m_iBottomMargin)); 770 } 771 772 void UISoftKeyboard::updateLayout() 773 { 774 if (!m_pContainerWidget) 775 return; 776 777 QSize containerSize(m_pContainerWidget->size()); 778 if (containerSize.width() == 0 || containerSize.height() == 0) 779 return; 780 781 float fMultiplierX = containerSize.width() / (float) m_iMaxRowWidth; 782 float fMultiplierY = containerSize.height() / (float) m_iTotalRowHeight; 783 float fMultiplier = fMultiplierX; 784 785 if (fMultiplier * m_iTotalRowHeight > containerSize.height()) 786 fMultiplier = fMultiplierY; 787 788 // int y = 0; 789 // int totalHeight = 0; 790 // int totalWidth = 0; 791 //for (int i = 0; i < layout.m_rows.size(); ++i) 792 { 793 // UISoftKeyboardRow *pRow = m_rows[i]; 794 // if (!pRow) 795 // continue; 796 // if(m_fKeepAspectRatio) 797 // { 798 // pRow->setGeometry(0, y, fMultiplier * pRow->unscaledWidth(), fMultiplier * pRow->unscaledHeight()); 799 // pRow->setVisible(true); 800 // y += fMultiplier * pRow->unscaledHeight(); 801 // totalWidth += fMultiplier * pRow->unscaledWidth(); 802 // totalHeight += fMultiplier * pRow->unscaledHeight(); 803 // } 804 // else 805 // { 806 // pRow->setGeometry(0, y, fMultiplierX * pRow->unscaledWidth(), fMultiplierY * pRow->unscaledHeight()); 807 // pRow->setVisible(true); 808 // y += fMultiplierY * pRow->unscaledHeight(); 809 // totalWidth += fMultiplierX * pRow->unscaledWidth(); 810 // totalHeight += fMultiplierY * pRow->unscaledHeight(); 811 // } 812 // pRow->updateLayout(); 813 } 807 int iInitialWidth = iMaxWidth + m_iRightMargin; 808 int iInitialHeight = iY + m_iBottomMargin; 809 m_pContainerWidget->setNewMinimumSize(QSize(iInitialWidth, iInitialHeight)); 810 m_pContainerWidget->setInitialSize(iInitialWidth, iInitialHeight); 814 811 } 815 812 -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78812 r78845 56 56 57 57 virtual void retranslateUi(); 58 virtual void resizeEvent(QResizeEvent *pEvent);59 58 60 59 private slots: … … 72 71 void loadSettings(); 73 72 void parseLayout(); 74 void updateLayout();75 73 CKeyboard& keyboard() const; 76 74 … … 79 77 UISoftKeyboardWidget *m_pContainerWidget; 80 78 QString m_strMachineName; 81 int m_iTotalRowHeight;82 int m_iMaxRowWidth;83 79 QVector<UISoftKeyboardKey*> m_pressedModifiers; 84 QVector<QVector<UISoftKeyboardKey*> > m_keys;85 80 bool m_fKeepAspectRatio; 86 81 -
trunk/src/VBox/Frontends/VirtualBox/xml/102_iso.xml
r78812 r78845 8 8 <scancode>0x01</scancode> 9 9 </key> 10 <space></space> 10 <space> 11 <width>50</width> 12 </space> 11 13 <key> 12 14 <keycap>F1</keycap> … … 94 96 </key> 95 97 </row> 98 <space> 99 <height>20</height> 100 </space> 96 101 <row> 97 102 <key> … … 179 184 <scancode>0x0e</scancode> 180 185 </key> 186 <space> 187 <width>25</width> 188 </space> 189 <key> 190 <keycap>PrtScn</keycap> 191 <position>121</position> 192 <scancode></scancode> 193 </key> 194 <key> 195 <keycap>ScrollLock</keycap> 196 <position>122</position> 197 <scancode>0x46</scancode> 198 </key> 199 <key> 200 <keycap>ScrollLock</keycap> 201 <position>122</position> 202 <scancode>0x46</scancode> 203 </key> 181 204 </row> 182 183 205 <row> 184 206 <key> … … 252 274 <key> 253 275 <width>85</width> 254 <height>10 0</height>276 <height>105</height> 255 277 <keycap>Enter</keycap> 256 278 <position>29</position> … … 258 280 <cutout> 259 281 <width>25</width> 260 <height>5 0</height>282 <height>55</height> 261 283 <corner>bottomLeft</corner> 262 284 </cutout> 263 285 </key> 286 <space> 287 <width>25</width> 288 </space> 289 <key> 290 <keycap>PrtScn</keycap> 291 <position>121</position> 292 <scancode></scancode> 293 </key> 294 <key> 295 <keycap>ScrollLock</keycap> 296 <position>122</position> 297 <scancode>0x46</scancode> 298 </key> 299 <key> 300 <keycap>ScrollLock</keycap> 301 <position>122</position> 302 <scancode>0x46</scancode> 303 </key> 264 304 </row> 305 <row> 306 <key> 307 <width>100</width> 308 <keycap>CapsLock</keycap> 309 <type>toggleable</type> 310 <position>30</position> 311 <scancode>0x3a</scancode> 312 </key> 313 <key> 314 <keycap>A</keycap> 315 <position>31</position> 316 <scancode>0x1e</scancode> 317 </key> 318 <key> 319 <keycap>S</keycap> 320 <position>32</position> 321 <scancode>0x1f</scancode> 322 </key> 323 <key> 324 <keycap>D</keycap> 325 <position>33</position> 326 <scancode>0x20</scancode> 327 </key> 328 <key> 329 <keycap>F</keycap> 330 <position>34</position> 331 <scancode>0x21</scancode> 332 </key> 333 <key> 334 <keycap>G</keycap> 335 <position>35</position> 336 <scancode>0x22</scancode> 337 </key> 338 <key> 339 <keycap>H</keycap> 340 <position>36</position> 341 <scancode>0x23</scancode> 342 </key> 343 <key> 344 <keycap>J</keycap> 345 <position>37</position> 346 <scancode>0x24</scancode> 347 </key> 348 <key> 349 <keycap>K</keycap> 350 <position>38</position> 351 <scancode>0x25</scancode> 352 </key> 353 <key> 354 <keycap>L</keycap> 355 <position>39</position> 356 <scancode>0x26</scancode> 357 </key> 358 <key> 359 <keycap>:</keycap> 360 <keycap>;</keycap> 361 <position>40</position> 362 <scancode>0x27</scancode> 363 </key> 364 <key> 365 <keycap>"</keycap> 366 <keycap>'</keycap> 367 <position>41</position> 368 <scancode>0x28</scancode> 369 </key> 370 <key> 371 <keycap>"</keycap> 372 <keycap>'</keycap> 373 <position>42</position> 374 <scancode>0x28</scancode> 375 </key> 376 </row> 377 <row> 378 <key> 379 <width>75</width> 380 <keycap>Shift</keycap> 381 <type>modifier</type> 382 <position>44</position> 383 <scancode>0x2a</scancode> 384 </key> 385 <key> 386 <keycap>Z</keycap> 387 <position>46</position> 388 <scancode>0x2c</scancode> 389 </key> 390 <key> 391 <keycap>X</keycap> 392 <position>47</position> 393 <scancode>0x2d</scancode> 394 </key> 395 <key> 396 <keycap>C</keycap> 397 <position>48</position> 398 <scancode>0x2e</scancode> 399 </key> 400 <key> 401 <keycap>V</keycap> 402 <position>49</position> 403 <scancode>0x2f</scancode> 404 </key> 405 <key> 406 <keycap>B</keycap> 407 <position>50</position> 408 <scancode>0x30</scancode> 409 </key> 410 <key> 411 <keycap>N</keycap> 412 <position>51</position> 413 <scancode>0x31</scancode> 414 </key> 415 <key> 416 <keycap>M</keycap> 417 <position>52</position> 418 <scancode>0x32</scancode> 419 </key> 420 <key> 421 <keycap><</keycap> 422 <keycap>,</keycap> 423 <position>53</position> 424 <scancode>0x33</scancode> 425 </key> 426 <key> 427 <keycap>></keycap> 428 <keycap>.</keycap> 429 <position>54</position> 430 <scancode>0x34</scancode> 431 </key> 432 <key> 433 <keycap>?</keycap> 434 <keycap>/</keycap> 435 <position>55</position> 436 <scancode>0x35</scancode> 437 </key> 438 <key> 439 <keycap>?</keycap> 440 <keycap>/</keycap> 441 <position>55</position> 442 <scancode>0x35</scancode> 443 </key> 444 <key> 445 <width>140</width> 446 <keycap>Shift</keycap> 447 <type>modifier</type> 448 <position>57</position> 449 <scancode>0x36</scancode> 450 </key> 451 <space> 452 <width>80</width> 453 </space> 454 <key> 455 <keycap>Up</keycap> 456 <position>83</position> 457 <scancode>0x35</scancode> 458 </key> 459 </row> 460 <row> 461 <key> 462 <width>105</width> 463 <keycap>Ctrl</keycap> 464 <type>modifier</type> 465 <position>58</position> 466 <scancode>0x1d</scancode> 467 </key> 468 <key> 469 <keycap>Win</keycap> 470 <type>modifier</type> 471 <scancodeprefix>0xe0</scancodeprefix> 472 <scancode>0x5b</scancode> 473 </key> 474 <key> 475 <position>60</position> 476 <keycap>Alt</keycap> 477 <type>modifier</type> 478 <scancode>0x38</scancode> 479 </key> 480 <key> 481 <width>330</width> 482 <position>61</position> 483 <scancode>0x39</scancode> 484 </key> 485 <key> 486 <keycap>AltGr</keycap> 487 <type>modifier</type> 488 <scancodeprefix>0xe0</scancodeprefix> 489 <scancode>0x38</scancode> 490 </key> 491 <key> 492 <keycap>Win</keycap> 493 <type>modifier</type> 494 <scancodeprefix>0xe0</scancodeprefix> 495 <scancode>0x5c</scancode> 496 </key> 497 <key> 498 <keycap>Menu</keycap> 499 <scancodeprefix>0xe0</scancodeprefix> 500 <scancode>0x5d</scancode> 501 </key> 502 <key> 503 <keycap>Ctrl</keycap> 504 <width>105</width> 505 <type>modifier</type> 506 <scancodeprefix>0xe0</scancodeprefix> 507 <scancode>0x1d</scancode> 508 </key> 509 <space> 510 <width>25</width> 511 </space> 512 <key> 513 <keycap>Left</keycap> 514 <position>79</position> 515 <scancode>0x35</scancode> 516 </key> 517 <key> 518 <keycap>Down</keycap> 519 <position>84</position> 520 <scancode>0x35</scancode> 521 </key> 522 <key> 523 <keycap>Right</keycap> 524 <position>89</position> 525 <scancode>0x35</scancode> 526 </key> 527 528 529 </row> 530 265 531 </layout>
Note:
See TracChangeset
for help on using the changeset viewer.