From 17a357d0327ebf0e8db43005ddc1fd0d4a1cf9b8 Mon Sep 17 00:00:00 2001 From: jihye Date: Sat, 11 Mar 2017 15:58:19 +0900 Subject: [PATCH] skin: control size of controller window - if increases the number of buttons, window extended horizontally Change-Id: Ib21c19ca3ff0bed6c53bc127b31eada4dd4d48a1 Signed-off-by: jihye --- tizen/src/ui/controller/dockingconview.cpp | 2 +- tizen/src/ui/controller/floatingconview.cpp | 2 +- tizen/src/ui/controller/generalpurposecon.cpp | 42 ++++++++++----- tizen/src/ui/controller/generalpurposecon.h | 5 +- tizen/src/ui/layout/controllerform.cpp | 10 ++++ tizen/src/ui/layout/controllerform.h | 4 ++ tizen/src/ui/skinpainter.cpp | 75 ++------------------------- tizen/src/ui/skinpainter.h | 8 +-- tizen/src/ui/xmllayoutparser.cpp | 58 ++++++++++++--------- 9 files changed, 88 insertions(+), 118 deletions(-) diff --git a/tizen/src/ui/controller/dockingconview.cpp b/tizen/src/ui/controller/dockingconview.cpp index d1e336c..a37507c 100644 --- a/tizen/src/ui/controller/dockingconview.cpp +++ b/tizen/src/ui/controller/dockingconview.cpp @@ -70,7 +70,7 @@ void DockingConView::createItems(ControllerForm *conForm) generalCon->createHeaderBarAndBorder(scene(), parent->getMainWindow()->getUiInfo(), false); QList buttons - = generalCon->createButtons(parentWidget(), conForm); + = generalCon->createButtons(scene(), parentWidget(), conForm); for (int i = 0; i < buttons.count(); i++) { HWKeyButton *button = buttons.at(i); diff --git a/tizen/src/ui/controller/floatingconview.cpp b/tizen/src/ui/controller/floatingconview.cpp index 277e3f1..1e14293 100644 --- a/tizen/src/ui/controller/floatingconview.cpp +++ b/tizen/src/ui/controller/floatingconview.cpp @@ -70,7 +70,7 @@ void FloatingConView::createItems(ControllerForm *conForm) generalCon->createHeaderBarAndBorder(scene(), parent->getMainWindow()->getUiInfo(), true); QList buttons - = generalCon->createButtons(parentWidget(), conForm); + = generalCon->createButtons(scene(), parentWidget(), conForm); for (int i = 0; i < buttons.count(); i++) { HWKeyButton *button = buttons.at(i); diff --git a/tizen/src/ui/controller/generalpurposecon.cpp b/tizen/src/ui/controller/generalpurposecon.cpp index 9a5c31e..5c7efbc 100644 --- a/tizen/src/ui/controller/generalpurposecon.cpp +++ b/tizen/src/ui/controller/generalpurposecon.cpp @@ -27,6 +27,7 @@ * */ +#include #include "config-host.h" #include "generalpurposecon.h" @@ -58,7 +59,7 @@ void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, UiInform } } -QList GeneralPurposeCon::createButtons(QWidget *parent, ControllerForm *form) +QList GeneralPurposeCon::createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form) { QPoint topLeft = form->getCenteralRect().topLeft(); topLeft.setX(topLeft.x() + GPC_LEFT_SPACING + GPC_BORDER_SIZE); @@ -67,32 +68,49 @@ QList GeneralPurposeCon::createButtons(QWidget *parent, Controlle QList buttonList; // H/W key list - createKeyList(parent, form->getKeyList(), topLeft, buttonList); + createKeyList(parent, form->getKeyList(), topLeft, form->getRowCount(), buttonList); topLeft.setY(topLeft.y() - + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * form->getKeyList().count()); + + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount()); // Menu key list for (int i = 0; i < form->getSubFormList().count(); i++) { + // draw separator + QPen borderPen(QColor(153, 153, 153), 1, Qt::SolidLine); + scene->addLine(0, topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2), + form->getCenteralRect().width() - GPC_BORDER_SIZE, + topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2), borderPen); + // ControllerForm *subForm = form->getSubFormList().at(i); - createKeyList(parent, subForm->getKeyList(), topLeft, buttonList); + createKeyList(parent, subForm->getKeyList(), topLeft, subForm->getRowCount(), buttonList); topLeft.setY(topLeft.y() - + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * subForm->getKeyList().count()); + + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount()); } return buttonList; } void GeneralPurposeCon::createKeyList(QWidget *parent, QList keyList, - QPoint topLeft, QList &buttonList) + QPoint topLeft, int count, QList &buttonList) { + if (count == 0) { + return; + } + HardwareKey *hwKey = NULL; HWKeyButton *keyButton = NULL; - for (int i = 0; i < keyList.count(); i++) { - hwKey = keyList.at(i); - if (hwKey != NULL) { + int index = 0; + int loop = ceil(keyList.count() / (float) count); + + for (int c = 0; c < loop; c++) { + for (int i = 0; i < count && index < keyList.count(); i++) { + hwKey = keyList.at(index++); + if (hwKey == NULL) { + continue; + } + keyButton = new HWKeyButton(parent, hwKey, - QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT)); + QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT)); QString tooltip = hwKey->getTooltip(); if (tooltip.isEmpty() == true) { if (hwKey->getKeySequence().isEmpty() == false) { @@ -104,8 +122,8 @@ void GeneralPurposeCon::createKeyList(QWidget *parent, QList keyL } keyButton->setToolTip(hwKey->getName() + " " + tooltip); - keyButton->move(topLeft.x(), topLeft.y() - + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * i); + keyButton->move(topLeft.x() + (GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING) * c, + topLeft.y() + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * i); buttonList.append(keyButton); } } diff --git a/tizen/src/ui/controller/generalpurposecon.h b/tizen/src/ui/controller/generalpurposecon.h index 8dfb18d..fe319e5 100644 --- a/tizen/src/ui/controller/generalpurposecon.h +++ b/tizen/src/ui/controller/generalpurposecon.h @@ -44,6 +44,7 @@ #define GPC_KEYBUTTON_HEIGHT (35) #define GPC_KEYBUTTON_VSPACING (15) #define GPC_KEYBUTTON_HSPACING (15) +#define GPC_MINIUM_HEIGHT (272) class GeneralPurposeCon { @@ -52,10 +53,10 @@ public: GeneralPurposeCon(); ~GeneralPurposeCon(); void createHeaderBarAndBorder(QGraphicsScene *scene, UiInformation *uiInfo, bool isFloating); - QList createButtons(QWidget *parent, ControllerForm *form); + QList createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form); private: - void createKeyList(QWidget *parent, QList keyList, QPoint topLeft, QList &buttonList); + void createKeyList(QWidget *parent, QList keyList, QPoint topLeft, int count, QList &buttonList); }; #endif // GENERALPURPOSECON_H diff --git a/tizen/src/ui/layout/controllerform.cpp b/tizen/src/ui/layout/controllerform.cpp index fffcf4d..96e8712 100644 --- a/tizen/src/ui/layout/controllerform.cpp +++ b/tizen/src/ui/layout/controllerform.cpp @@ -49,6 +49,16 @@ QList &ControllerForm::getSubFormList() return subFormList; } +int ControllerForm::getRowCount() +{ + return rowCount; +} + +void ControllerForm::setRowCount(int count) +{ + rowCount = count; +} + ControllerForm::~ControllerForm() { qDebug("destroy con layout"); diff --git a/tizen/src/ui/layout/controllerform.h b/tizen/src/ui/layout/controllerform.h index 9cb3b4f..8be3e4e 100644 --- a/tizen/src/ui/layout/controllerform.h +++ b/tizen/src/ui/layout/controllerform.h @@ -46,7 +46,11 @@ public: QRect getCenteralRect(); QList &getSubFormList(); + int getRowCount(); + void setRowCount(int count); + private: + int rowCount; // for general purpose skin QRect centeralRect; QList subFormList; }; diff --git a/tizen/src/ui/skinpainter.cpp b/tizen/src/ui/skinpainter.cpp index 3ee51ed..5428c17 100644 --- a/tizen/src/ui/skinpainter.cpp +++ b/tizen/src/ui/skinpainter.cpp @@ -33,22 +33,12 @@ #include "skinpainter.h" #include "resource/ui_strings.h" -#define COLOR_TAG_SIZE (4) - -SkinPainter::SkinPainter(const QString &patchPath, - QSize centerPatch, int degree, QPoint tagLeftTop, QColor tagColor) -{ - QString path = ":/images/" + patchPath + "/"; - - drawSkin(path, centerPatch, degree, tagLeftTop, tagColor); -} - -SkinPainter::SkinPainter(QSize centerPatch, int degree, QList separators) +SkinPainter::SkinPainter(QSize centerPatch, int degree) { - drawSkin(centerPatch, degree, separators); + drawSkin(centerPatch, degree); } -void SkinPainter::drawSkin(QSize center, int degree, QList separators) { +void SkinPainter::drawSkin(QSize center, int degree) { qDebug() << "draw skin surface"; QRect centeralRect(0, 0, center.width(), center.height()); @@ -58,13 +48,6 @@ void SkinPainter::drawSkin(QSize center, int degree, QList separato QPainter painter(&image); painter.fillRect(centeralRect, QBrush(QColor(244, 244, 244))); - // add separators - for (int i = 0; i < separators.count(); i++) { - Separator *s = separators.at(i); - painter.setPen(s->pen); - painter.drawLine(0, s->hOffset, center.width(), s->hOffset); - } - /* rotate */ QTransform transform; skin = new QPixmap(image.transformed(transform.rotate(degree))); @@ -73,58 +56,6 @@ void SkinPainter::drawSkin(QSize center, int degree, QList separato transform.mapRect(centeralRect).size()); } -void SkinPainter::drawSkin(QString patchPath, QSize center, int degree, - QPoint tagLeftTop, QColor tagColor) -{ - qDebug() << "load skin patches from:" << patchPath; - - QImage LT(patchPath + GENERAL_SKIN_LEFTTOP_FILE); - QImage LC(patchPath + GENERAL_SKIN_LEFTCENTER_FILE); - QImage LB(patchPath + GENERAL_SKIN_LEFTBOTTOM_FILE); - QImage TC(patchPath + GENERAL_SKIN_TOPCENTER_FILE); - QImage BC(patchPath + GENERAL_SKIN_BOTTOMCENTER_FILE); - QImage RT(patchPath + GENERAL_SKIN_RIGHTTOP_FILE); - QImage RC(patchPath + GENERAL_SKIN_RIGHTCENTER_FILE); - QImage RB(patchPath + GENERAL_SKIN_RIGHTBOTTOM_FILE); - - QRect centeralRect0(LT.width(), LT.height(), center.width(), center.height()); - - QPixmap image(center.width() + (LT.width() * 2), - center.height() + (LT.height() * 2)); - image.fill(Qt::transparent); - - QPainter painter(&image); - - /* top side */ - painter.drawImage(0, 0, LT); - painter.drawImage(QRect(LT.width(), 0, center.width(), LT.height()), TC); - painter.drawImage(center.width() + LT.width(), 0, RT); - - /* middle side */ - painter.drawImage(QRect(0, LT.height(), LT.width(), center.height()), LC); - painter.fillRect(centeralRect0, QBrush(QColor(38, 38, 38))); - painter.drawImage(QRect( - center.width() + LT.width(), LT.height(), RT.width(), center.height()), RC); - - /* bottom side */ - painter.drawImage(0, center.height() + LT.height(), LB); - painter.drawImage(QRect( - LT.width(), center.height() + LT.height(), center.width(), LB.height()), BC); - painter.drawImage(center.width() + LT.width(), center.height() + LT.height(), RB); - - /* color tag */ - painter.setPen(tagColor); - painter.setBrush(QBrush(tagColor)); - painter.drawEllipse(tagLeftTop, COLOR_TAG_SIZE, COLOR_TAG_SIZE); - - /* rotate */ - QTransform transform; - skin = new QPixmap(image.transformed(transform.rotate(degree))); - - centeralRect = QRect( - centeralRect0.topLeft(), transform.mapRect(centeralRect0).size()); -} - QImage SkinPainter::getSkinImage() const { return skin->toImage(); diff --git a/tizen/src/ui/skinpainter.h b/tizen/src/ui/skinpainter.h index 03e91fc..8b5adad 100644 --- a/tizen/src/ui/skinpainter.h +++ b/tizen/src/ui/skinpainter.h @@ -43,18 +43,14 @@ struct Separator class SkinPainter { public: - SkinPainter(const QString &patchPath, QSize centerPatch, int degree, - QPoint tagLeftTop, QColor tagColor); - SkinPainter(QSize centerPatch, int degree, QList separators); + SkinPainter(QSize centerPatch, int degree); ~SkinPainter(); QImage getSkinImage() const; QRect getCenteralRect(); private: - void drawSkin(QString patchPath, QSize center, int degree, - QPoint tagLeftTop, QColor tagColor); - void drawSkin(QSize center, int degree, QList separators); + void drawSkin(QSize center, int degree); QPixmap *skin; QRect centeralRect; diff --git a/tizen/src/ui/xmllayoutparser.cpp b/tizen/src/ui/xmllayoutparser.cpp index c2c4b20..9664e3b 100644 --- a/tizen/src/ui/xmllayoutparser.cpp +++ b/tizen/src/ui/xmllayoutparser.cpp @@ -28,6 +28,7 @@ * */ +#include #include "config-host.h" #include "xmllayoutparser.h" @@ -379,9 +380,8 @@ int XmlLayoutParser::parseMainFormList(QXmlStreamReader &xml, /* image validation */ if (form->skinImg[LayoutForm::normal].size() == QSize(0, 0)) { QDEBUG_INDENT(depth + 1) << "(general purpose skin type)"; - QList list; SkinPainter painter(uiInfo->getResolution(), - form->getDpyType()->getAngle(), list); + form->getDpyType()->getAngle()); form->setGeneralPurpose(true); form->skinImg[LayoutForm::normal] = painter.getSkinImage(); @@ -800,34 +800,44 @@ QString XmlLayoutParser::parseControllerUI(QXmlStreamReader &xml) void XmlLayoutParser::makeGeneralCon(ControllerForm *form) { - int keyCount = form->getKeyList().count(); + int skinHeight = uiInfo->getResolution().height() / 2; + if (skinHeight < GPC_MINIUM_HEIGHT) { + skinHeight = GPC_MINIUM_HEIGHT; + } else { + // TODO: neet to determine extra space size. + // add extra space to the controller relative to several button size or height. + skinHeight += (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * 3; + } + + int hOffset = GPC_HEAD_SPACING + GPC_BORDER_SIZE + GPC_TAIL_SPACING; + + int conWidth = GPC_BORDER_SIZE * 2; + int conHeight = 0; + int columnCount = 0; + int keyCount = 0; + + do { + columnCount++; - int width = GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING + GPC_BORDER_SIZE * 2; - int height = GPC_HEAD_SPACING + GPC_BORDER_SIZE; - height += (GPC_KEYBUTTON_HEIGHT * keyCount) + + conWidth += (GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING); + conHeight = hOffset; + + keyCount = ceil(form->getKeyList().count() / (float)columnCount); + form->setRowCount(keyCount); + conHeight += (GPC_KEYBUTTON_HEIGHT * keyCount) + (GPC_KEYBUTTON_VSPACING * (keyCount - 1)); - // add sub form - QList sList; - QPen pen(QColor(205, 205, 205), 1, Qt::SolidLine); - for (int i = 0; i < form->getSubFormList().count(); i++) { - // for separator - Separator *s = new Separator(); - s->pen = pen; - s->hOffset = height + GPC_KEYBUTTON_VSPACING / 2; - sList.append(s); - - ControllerForm *subForm = form->getSubFormList().at(i); - keyCount = subForm->getKeyList().count(); - - height += (GPC_KEYBUTTON_HEIGHT * keyCount) + - (GPC_KEYBUTTON_VSPACING * keyCount); - } + for (int i = 0; i < form->getSubFormList().count(); i++) { + ControllerForm *subForm = form->getSubFormList().at(i); - height += GPC_TAIL_SPACING; + keyCount = ceil(subForm->getKeyList().count() / (float) columnCount); + subForm->setRowCount(keyCount); + conHeight += (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * keyCount; + } - SkinPainter painter(QSize(width, qMax(height, QT_LAYOUT_MINIMUM - 20)), 0, sList); + } while (skinHeight < conHeight); + SkinPainter painter(QSize(conWidth, qMax(conHeight, QT_LAYOUT_MINIMUM - 20)), 0); form->skinImg[LayoutForm::normal] = painter.getSkinImage(); form->setCenteralRect(painter.getCenteralRect()); form->setGeneralPurpose(true); -- 2.7.4