SVN commit 950031 by ruberg: Now uses QGridLayout for positioning the keys M +72 -2 widget.cpp M +5 -0 widget.h --- trunk/playground/base/plasma/applets/plasmaboard/widget.cpp #950030:950031 @@ -37,6 +37,9 @@ setPreferredSize(500, 200); setMinimumSize(300,150); setMaximumSize(3000,3000); + width = 500; + height = 200; + setCacheMode(QGraphicsItem::DeviceCoordinateCache); initPC105Layout(); @@ -62,6 +65,8 @@ delete alphaKeys[i]; i++; } + + delete layout; } void PlasmaboardWidget::init(){ @@ -88,6 +93,70 @@ QObject::connect(funcKeys[3], SIGNAL( clicked() ), this, SLOT( switchCaps() ) ); QObject::connect(funcKeys[10], SIGNAL( clicked() ), this, SLOT( switchAlternative() ) ); + int numberOfCols = 30; + int numberOfRows = 5; + + QGraphicsGridLayout *layout = new QGraphicsGridLayout(this); + + int x; + int row = 0; + for(x = 0; x<=12; x++){ + layout->addItem(alphaKeys[x], row, x*2, 1, 2, Qt::AlignLeft); + } + layout->addItem(funcKeys[0], row, x*2, 1, 4, Qt::AlignLeft); + + row++; + + layout->addItem(funcKeys[1], row, 0, 1, 3, Qt::AlignLeft); + int t = 3; + for(x = 13; x<=24; x++){ + layout->addItem(alphaKeys[x], row, t, 1, 2, Qt::AlignLeft); + t+=2; + } + layout->addItem(funcKeys[2], row, t+1, 2, 2, Qt::AlignLeft); + + row++; + + layout->addItem(funcKeys[3], row, 0, 1, 4, Qt::AlignLeft); + t = 4; + for(x = 25; x<=36; x++){ + layout->addItem(alphaKeys[x], row, t, 1, 2, Qt::AlignLeft); + t+=2; + } + + row++; + + layout->addItem(funcKeys[4], row, 0, 1, 3, Qt::AlignLeft); + t = 3; + for(x = 37; x<=47; x++){ + layout->addItem(alphaKeys[x], row, t, 1, 2, Qt::AlignLeft); + t+=2; + } + layout->addItem(funcKeys[5], row, t, 1, 5, Qt::AlignLeft); + + row++; + + layout->addItem(funcKeys[6], row, 0, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[7], row, 2, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[8], row, 4, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[9], row, 6, 1, 14, Qt::AlignLeft); + layout->addItem(funcKeys[10], row, 20, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[11], row, 22, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[12], row, 24, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[13], row, 26, 1, 2, Qt::AlignLeft); + layout->addItem(funcKeys[14], row, 28, 1, 2, Qt::AlignLeft); + + for(int i = 0; isetColumnPreferredWidth(i,width/numberOfCols); + } + for(int i = 0; isetRowPreferredHeight(i,height/numberOfRows); + layout->setRowMaximumHeight(i,100); + } + + layout->setSpacing(0); + setLayout(layout); + } void PlasmaboardWidget::initLatinKeymap(){ @@ -183,10 +252,11 @@ p->setRenderHint(QPainter::SmoothPixmapTransform); p->setRenderHint(QPainter::Antialiasing); + /* int heightUnit = (contentsRect().height() / 5); float widthUnit = (contentsRect().width())/ 31; - /* top row */ + // top row int i = 0; int x = 0; while( i < 13) { @@ -231,7 +301,7 @@ funcKeys[12]->setGeometry(QRectF(24*widthUnit, 4*heightUnit, 2*widthUnit, heightUnit)); funcKeys[13]->setGeometry(QRectF(26*widthUnit, 4*heightUnit, 2*widthUnit, heightUnit)); funcKeys[14]->setGeometry(QRectF(28*widthUnit, 4*heightUnit, 2*widthUnit, heightUnit)); - + */ p->restore(); } --- trunk/playground/base/plasma/applets/plasmaboard/widget.h #950030:950031 @@ -34,6 +34,7 @@ class AlphaNumKey; class FuncKey; class QChar; +class QGraphicsGridLayout; // Define our plasma Applet class PlasmaboardWidget : public Plasma::Applet @@ -64,6 +65,10 @@ bool isLevel2; bool isAlternative; bool isLocked; + QGraphicsGridLayout *layout; + + int width; + int height; };