skin: control size of controller window
authorjihye <jihye424.kim@samsung.com>
Sat, 11 Mar 2017 06:58:19 +0000 (15:58 +0900)
committerjihye <jihye424.kim@samsung.com>
Thu, 16 Mar 2017 07:48:04 +0000 (16:48 +0900)
- if increases the number of buttons, window extended horizontally

Change-Id: Ib21c19ca3ff0bed6c53bc127b31eada4dd4d48a1
Signed-off-by: jihye <jihye424.kim@samsung.com>
tizen/src/ui/controller/dockingconview.cpp
tizen/src/ui/controller/floatingconview.cpp
tizen/src/ui/controller/generalpurposecon.cpp
tizen/src/ui/controller/generalpurposecon.h
tizen/src/ui/layout/controllerform.cpp
tizen/src/ui/layout/controllerform.h
tizen/src/ui/skinpainter.cpp
tizen/src/ui/skinpainter.h
tizen/src/ui/xmllayoutparser.cpp

index d1e336c..a37507c 100644 (file)
@@ -70,7 +70,7 @@ void DockingConView::createItems(ControllerForm *conForm)
 
         generalCon->createHeaderBarAndBorder(scene(), parent->getMainWindow()->getUiInfo(), false);
         QList<HWKeyButton *> buttons
-                    = generalCon->createButtons(parentWidget(), conForm);
+                    = generalCon->createButtons(scene(), parentWidget(), conForm);
 
         for (int i = 0; i < buttons.count(); i++) {
             HWKeyButton *button = buttons.at(i);
index 277e3f1..1e14293 100644 (file)
@@ -70,7 +70,7 @@ void FloatingConView::createItems(ControllerForm *conForm)
 
         generalCon->createHeaderBarAndBorder(scene(), parent->getMainWindow()->getUiInfo(), true);
         QList<HWKeyButton *> buttons
-                    = generalCon->createButtons(parentWidget(), conForm);
+                    = generalCon->createButtons(scene(), parentWidget(), conForm);
 
         for (int i = 0; i < buttons.count(); i++) {
             HWKeyButton *button = buttons.at(i);
index 9a5c31e..5c7efbc 100644 (file)
@@ -27,6 +27,7 @@
  *
  */
 
+#include <math.h>
 #include "config-host.h"
 
 #include "generalpurposecon.h"
@@ -58,7 +59,7 @@ void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, UiInform
     }
 }
 
-QList<HWKeyButton *> GeneralPurposeCon::createButtons(QWidget *parent, ControllerForm *form)
+QList<HWKeyButton *> 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<HWKeyButton *> GeneralPurposeCon::createButtons(QWidget *parent, Controlle
     QList<HWKeyButton *> 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<HardwareKey *> keyList,
-                                        QPoint topLeft, QList<HWKeyButton *> &buttonList)
+                                        QPoint topLeft, int count, QList<HWKeyButton *> &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<HardwareKey *> 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);
         }
     }
index 8dfb18d..fe319e5 100644 (file)
@@ -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<HWKeyButton *> createButtons(QWidget *parent, ControllerForm *form);
+    QList<HWKeyButton *> createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form);
 
 private:
-    void createKeyList(QWidget *parent, QList<HardwareKey *> keyList, QPoint topLeft, QList<HWKeyButton *> &buttonList);
+    void createKeyList(QWidget *parent, QList<HardwareKey *> keyList, QPoint topLeft, int count, QList<HWKeyButton *> &buttonList);
 };
 
 #endif // GENERALPURPOSECON_H
index fffcf4d..96e8712 100644 (file)
@@ -49,6 +49,16 @@ QList<ControllerForm *> &ControllerForm::getSubFormList()
     return subFormList;
 }
 
+int ControllerForm::getRowCount()
+{
+    return rowCount;
+}
+
+void ControllerForm::setRowCount(int count)
+{
+    rowCount = count;
+}
+
 ControllerForm::~ControllerForm()
 {
     qDebug("destroy con layout");
index 9cb3b4f..8be3e4e 100644 (file)
@@ -46,7 +46,11 @@ public:
     QRect getCenteralRect();
     QList<ControllerForm *> &getSubFormList();
 
+    int getRowCount();
+    void setRowCount(int count);
+
 private:
+    int rowCount; // for general purpose skin
     QRect centeralRect;
     QList<ControllerForm *> subFormList;
 };
index 3ee51ed..5428c17 100644 (file)
 #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<Separator *> separators)
+SkinPainter::SkinPainter(QSize centerPatch, int degree)
 {
-    drawSkin(centerPatch, degree, separators);
+    drawSkin(centerPatch, degree);
 }
 
-void SkinPainter::drawSkin(QSize center, int degree, QList<Separator *> 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<Separator *> 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<Separator *> 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();
index 03e91fc..8b5adad 100644 (file)
@@ -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<Separator *> 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<Separator *> separators);
+    void drawSkin(QSize center, int degree);
 
     QPixmap *skin;
     QRect centeralRect;
index c2c4b20..9664e3b 100644 (file)
@@ -28,6 +28,7 @@
  *
  */
 
+#include <math.h>
 #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<Separator *> 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<Separator *> 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);