- Timestamp:
- May 20, 2019 11:17:50 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78567 r78595 19 19 #include <QApplication> 20 20 #include <QFile> 21 #include <QMenu>22 21 #include <QPushButton> 23 #include <QSplitter>24 22 #include <QXmlStreamReader> 25 23 #include <QVBoxLayout> … … 35 33 #include "CEventSource.h" 36 34 35 struct SoftKeyboardKey 36 { 37 int m_iWidth; 38 QString m_strLabel; 39 LONG m_scanCode; 40 }; 41 42 struct SoftKeyboardRow 43 { 44 int m_iHeight; 45 QList<SoftKeyboardKey> m_keys; 46 }; 47 48 struct SoftKeyboardLayout 49 { 50 QList<SoftKeyboardRow> m_rows; 51 }; 52 37 53 /********************************************************************************************************************************* 38 54 * UIKeyboardLayoutReader definition. * … … 44 60 public: 45 61 46 bool parseXMLFile(const QString &strFileName );62 bool parseXMLFile(const QString &strFileName, SoftKeyboardLayout &layout); 47 63 48 64 private: 49 65 50 bool parseRow( );51 bool parseKey( );66 bool parseRow(SoftKeyboardLayout &layout); 67 bool parseKey(SoftKeyboardRow &row); 52 68 QXmlStreamReader m_xmlReader; 53 69 }; … … 64 80 public: 65 81 66 UISoftKeyboardKey(QWidget *pParent); 82 UISoftKeyboardKey(QWidget *pParent = 0); 83 void setAspectRatio(float fRatio); 84 85 protected: 86 87 virtual void resizeEvent(QResizeEvent *pEvent); 88 89 private: 90 91 float m_fAspectRatio; 67 92 }; 68 93 … … 71 96 *********************************************************************************************************************************/ 72 97 73 bool UIKeyboardLayoutReader::parseXMLFile(const QString &strFileName )98 bool UIKeyboardLayoutReader::parseXMLFile(const QString &strFileName, SoftKeyboardLayout &layout) 74 99 { 75 100 QFile xmlFile(strFileName); … … 88 113 { 89 114 if (m_xmlReader.name() == "row") 90 parseRow( );115 parseRow(layout); 91 116 else 92 117 m_xmlReader.skipCurrentElement(); … … 96 121 } 97 122 98 bool UIKeyboardLayoutReader::parseRow() 99 { 123 bool UIKeyboardLayoutReader::parseRow(SoftKeyboardLayout &layout) 124 { 125 layout.m_rows.append(SoftKeyboardRow()); 126 SoftKeyboardRow &row = layout.m_rows.last(); 100 127 while (m_xmlReader.readNextStartElement()) 101 128 { 102 129 if (m_xmlReader.name() == "key") 103 parseKey(); 130 parseKey(row); 131 else if (m_xmlReader.name() == "height") 132 row.m_iHeight = m_xmlReader.readElementText().toInt(); 104 133 else 105 134 m_xmlReader.skipCurrentElement(); 106 135 } 107 108 136 return true; 109 137 } 110 138 111 bool UIKeyboardLayoutReader::parseKey() 112 { 139 bool UIKeyboardLayoutReader::parseKey(SoftKeyboardRow &row) 140 { 141 row.m_keys.append(SoftKeyboardKey()); 142 SoftKeyboardKey &key = row.m_keys.last(); 113 143 while (m_xmlReader.readNextStartElement()) 114 144 { 115 116 // if (m_xmlReader.name() == "key") 117 // parseKey(); 118 // else 145 if (m_xmlReader.name() == "width") 146 key.m_iWidth = m_xmlReader.readElementText().toInt(); 147 else if (m_xmlReader.name() == "label") 148 key.m_strLabel = m_xmlReader.readElementText(); 149 else if (m_xmlReader.name() == "scancode") 150 key.m_scanCode = m_xmlReader.readElementText().toInt(); 151 else 119 152 m_xmlReader.skipCurrentElement(); 120 153 } 121 122 154 return true; 123 155 } … … 127 159 *********************************************************************************************************************************/ 128 160 129 UISoftKeyboardKey::UISoftKeyboardKey(QWidget *pParent )161 UISoftKeyboardKey::UISoftKeyboardKey(QWidget *pParent /* = 0 */) 130 162 :QPushButton(pParent) 131 { 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); 132 178 } 133 179 … … 141 187 :QIWithRetranslateUI<QWidget>(pParent) 142 188 , m_pMainLayout(0) 189 , m_pContainerLayout(0) 143 190 , m_pToolBar(0) 144 191 , m_fShowToolbar(fShowToolbar) 145 192 , m_strMachineName(strMachineName) 146 193 { 194 prepareObjects(); 147 195 parseLayout(); 148 prepareObjects();149 196 prepareConnections(); 150 197 prepareToolBar(); … … 162 209 } 163 210 211 void UISoftKeyboard::resizeEvent(QResizeEvent *pEvent) 212 { 213 QIWithRetranslateUI<QWidget>::resizeEvent(pEvent); 214 } 215 164 216 void UISoftKeyboard::prepareObjects() 165 217 { 218 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 166 219 /* Create layout: */ 167 m_pMainLayout = new QVBoxLayout(this); 220 221 m_pMainLayout = new QHBoxLayout(this); 168 222 if (!m_pMainLayout) 169 223 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); 170 235 171 236 /* Configure layout: */ 172 m_pMainLayout->setSpacing(0); 237 173 238 } 174 239 … … 191 256 void UISoftKeyboard::parseLayout() 192 257 { 258 if (!m_pContainerLayout) 259 return; 260 193 261 UIKeyboardLayoutReader reader; 194 if (!reader.parseXMLFile(":/us_layout.xml")) 195 { 262 SoftKeyboardLayout layout; 263 if (!reader.parseXMLFile(":/us_layout.xml", layout)) 264 return; 265 266 for (int i = 0; i < layout.m_rows.size(); ++i) 267 { 268 QHBoxLayout *pRowLayout = new QHBoxLayout; 269 pRowLayout->setSpacing(0); 270 for (int j = 0; j < layout.m_rows[i].m_keys.size(); ++j) 271 { 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); 276 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); 285 } 286 //pRowLayout->addStretch(1); 287 //m_pContainerLayout->setColumnStretch(layout.m_rows[i].m_keys.size()-1, 1); 288 m_pContainerLayout->addLayout(pRowLayout); 196 289 } 197 290 } -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78567 r78595 36 36 /* Forward declarations: */ 37 37 class UISoftKeyboardKey; 38 class QHBoxLayout; 38 39 class QVBoxLayout; 39 40 class UIToolBar; 41 40 42 41 43 class UISoftKeyboard : public QIWithRetranslateUI<QWidget> … … 51 53 protected: 52 54 53 void retranslateUi(); 55 virtual void retranslateUi(); 56 virtual void resizeEvent(QResizeEvent *pEvent); 54 57 55 58 private slots: … … 64 67 void parseLayout(); 65 68 66 QVBoxLayout *m_pMainLayout; 69 QHBoxLayout *m_pMainLayout; 70 QVBoxLayout *m_pContainerLayout; 67 71 UIToolBar *m_pToolBar; 68 72 const bool m_fShowToolbar; -
trunk/src/VBox/Frontends/VirtualBox/xml/us_layout.xml
r78567 r78595 4 4 <height>50</height> 5 5 <key> 6 <width> 30</width>6 <width>50</width> 7 7 <label>Key1</label> 8 8 <scancode>X11</scancode> 9 9 </key> 10 <key> 11 <width>150</width> 12 <label>Key2</label> 13 <scancode>X11</scancode> 14 </key> 15 <key> 16 <width>20</width> 17 <label>Key3</label> 18 <scancode>X11</scancode> 19 </key> 20 <key> 21 <width>50</width> 22 <label>Key4</label> 23 <scancode>X11</scancode> 24 </key> 25 10 26 </row> 27 28 <row> 29 <height>30</height> 30 <key> 31 <width>150</width> 32 <label>Key2</label> 33 <scancode>X11</scancode> 34 </key> 35 <key> 36 <width>20</width> 37 <label>Key3</label> 38 <scancode>X11</scancode> 39 </key> 40 <key> 41 <width>50</width> 42 <label>Key4</label> 43 <scancode>X11</scancode> 44 </key> 45 46 </row> 47 11 48 </layout>
Note:
See TracChangeset
for help on using the changeset viewer.