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);
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);
*
*/
+#include <math.h>
#include "config-host.h"
#include "generalpurposecon.h"
}
}
-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);
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) {
}
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);
}
}
#define GPC_KEYBUTTON_HEIGHT (35)
#define GPC_KEYBUTTON_VSPACING (15)
#define GPC_KEYBUTTON_HSPACING (15)
+#define GPC_MINIUM_HEIGHT (272)
class GeneralPurposeCon
{
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
return subFormList;
}
+int ControllerForm::getRowCount()
+{
+ return rowCount;
+}
+
+void ControllerForm::setRowCount(int count)
+{
+ rowCount = count;
+}
+
ControllerForm::~ControllerForm()
{
qDebug("destroy con layout");
QRect getCenteralRect();
QList<ControllerForm *> &getSubFormList();
+ int getRowCount();
+ void setRowCount(int count);
+
private:
+ int rowCount; // for general purpose skin
QRect centeralRect;
QList<ControllerForm *> subFormList;
};
#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());
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)));
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();
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;
*
*/
+#include <math.h>
#include "config-host.h"
#include "xmllayoutparser.h"
/* 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();
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);