QString rotaryImageFileName = xml.readElementText();
qDebug() << "-" << ROTARY_IMG_KEYWORD << ":" << rotaryImageFileName;
- if (form->rotaryImg.load(
- xmlPath + QDir::separator() + rotaryImageFileName) == false) {
+ form->setRotaryImage(new QPixmap(
+ xmlPath + QDir::separator() + rotaryImageFileName));
+ if (form->getRotaryImage()->isNull() == true) {
qWarning() << "failed to load rotary image";
}
} else if (xml.name() == KEYLIST_KEYWORD) {
obj-$(CONFIG_QT) += skinbezelitem.o
obj-$(CONFIG_QT) += skinkeyitem.o moc_skinkeyitem.o
obj-$(CONFIG_QT) += skinview.o
+obj-$(CONFIG_QT) += rotaryview.o
obj-$(CONFIG_QT) += skinpainter.o
obj-$(CONFIG_QT) += uiinformation.o
obj-$(CONFIG_QT) += uistate.o
rect.y() * scaleFactor,
rect.width() * scaleFactor,
rect.height() * scaleFactor);
-
- if (maskImage.size() != QSize(0, 0)) {
- qDebug("set a mask to display");
- widget->setMask(maskImage.mask());
- }
}
void DisplayBase::handlePaint(QPaintEvent *event)
qt5_window_height = widget->height();
qt5_graphic_hw_invalidate();
+
+ /* masking */
+ if (maskImage.size() != QSize(0, 0)) {
+ qDebug("set a mask to display");
+ widget->setMask(maskImage.mask());
+ }
}
QPoint DisplayBase::getGuestPos(QPoint hostPos)
MainForm::MainForm(const QString &name) : LayoutForm(name)
{
this->displayType = NULL;
+ this->rotaryImg = NULL;
+}
+
+void MainForm::setRotaryImage(QPixmap *image)
+{
+ rotaryImg = image;
+}
+
+QPixmap *MainForm::getRotaryImage()
+{
+ return rotaryImg;
}
MainForm::~MainForm()
delete displayType;
}
+ if (rotaryImg != NULL) {
+ delete rotaryImg;
+ }
+
for (int i = 0; i < keyList.count(); i++) {
delete keyList.at(i);
}
MainForm(const QString &name);
~MainForm();
+ void setRotaryImage(QPixmap *image);
+ QPixmap *getRotaryImage();
+
DisplayType *displayType;
QImage skinImg[2];
- QImage rotaryImg;
QList<HardwareKey *> keyList;
enum SkinImgType {
normal = 0,
pressed = 1
};
+
+private:
+ QPixmap *rotaryImg;
};
#endif // MAINFORM_H
this->popupMenu = NULL;
this->display = NULL;
+ this->rotary = NULL;
this->swapper = NULL;
this->swapperThread = NULL;
skinView = new SkinView(skinScene, this);
winLayout->addWidget(skinView);
+ /* rotary */
+ MainForm *form = NULL;
+ bool needRotary = false;
+ for(int i = 0; i < uiInfo->mainFormList.count(); i++) {
+ form = uiInfo->mainFormList.at(i);
+ if (form->getRotaryImage() != NULL &&
+ form->getRotaryImage()->isNull() == false) {
+ needRotary = true;
+ break;
+ }
+ }
+ if (needRotary == true) {
+ rotary = createRotary();
+ }
+
/* display */
display = createDisplay(uiInfo->getMainFormDisplayType());
DisplayBase *MainWindow::createDisplay(DisplayType *displayForm)
{
+ qDebug("create a display");
+
DisplayBase *displayWidget = NULL;
if (qt5GLContext) { /* on-screen rendering */
*/
QGLContext *context = new QGLContext(format);
- displayWidget = new DisplayGLWidget(skinView, context,
+ displayWidget = new DisplayGLWidget(this, context,
displayForm, getUIState()->getScaleFactor());
context->setFormat(format);
swapperThread->start();
} else { /* off-screen rendering */
- DisplaySWWidget *widget = new DisplaySWWidget(skinView,
+ DisplaySWWidget *widget = new DisplaySWWidget(this,
displayForm, getUIState()->getScaleFactor());
screenWidget = widget;
return displayWidget;
}
+RotaryView *MainWindow::createRotary()
+{
+ qDebug("create a rotary");
+ return new RotaryView(this);
+}
+
void MainWindow::startDisplaySwapper()
{
if (swapper != NULL) {
}
resize(uiInfo->getUiSize());
+
skinView->update();
+ if (rotary != NULL) {
+ rotary->update();
+ }
if (display != NULL) {
display->switchForm(uiInfo->getMainFormDisplayType());
}
resize(uiInfo->getUiSize());
+
skinView->update();
+ if (rotary != NULL) {
+ rotary->update();
+ }
if (display != NULL) {
display->scaleForm(getUIState()->getScaleFactor());
swapperThread->quit();
swapperThread->wait();
+
+ if (rotary != NULL) {
+ delete rotary;
+ rotary = NULL;
+ }
}
void MainWindow::closeEvent(QCloseEvent *event)
#include "menu/contextmenu.h"
#include "skinview.h"
#include "displaybase.h"
-#include "skinbezelitem.h"
+#include "rotaryview.h"
#include "uiinformation.h"
#include "controller/dockingcontroller.h"
#include "controller/floatingcontroller.h"
private:
DisplayBase *createDisplay(DisplayType *displayForm);
+ RotaryView *createRotary();
/* windowing */
QHBoxLayout *winLayout;
QGraphicsScene *skinScene;
SkinView *skinView;
DisplayBase *display;
+ RotaryView *rotary;
+
ContextMenu *popupMenu;
QThread *swapperThread;
DisplaySwapper *swapper;
--- /dev/null
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <QWidget>
+
+#include "rotaryview.h"
+#include "mainwindow.h"
+
+RotaryView::RotaryView(QWidget *parent) :
+ QGraphicsView(new QGraphicsScene(parent), parent)
+{
+ this->win = (MainWindow *)parent;
+ this->rotaryImg = win->uiInfo->getMainForm()->getRotaryImage();
+ this->grabPos = QPoint(-1, -1);
+ this->grabAngle = 0;
+ this->rotaryDegree = 0;
+
+ setStyleSheet("background-color: rgb(189, 189, 189); border-style: none");
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setAlignment(Qt::AlignLeft | Qt::AlignTop);
+
+ update();
+}
+
+void RotaryView::createItems()
+{
+ rotaryItem = new QGraphicsPixmapItem(*rotaryImg);
+ rotaryItem->setTransformOriginPoint(
+ rotaryImg->width() / 2, rotaryImg->height() / 2);
+ rotaryItem->setRotation(rotaryDegree);
+ scene()->addItem(rotaryItem);
+}
+
+void RotaryView::update()
+{
+ scene()->clear();
+
+ rotaryImg = win->uiInfo->getMainForm()->getRotaryImage();
+ const QRect displayRect = win->uiInfo->getMainFormDisplayType()->getRect();
+
+ /* repositioning & resizing */
+ const int alignOffsetX = (rotaryImg->width() - displayRect.width()) / 2;
+ const int alignOffsetY = (rotaryImg->height() - displayRect.height()) / 2;
+
+ setGeometry(
+ displayRect.x() - alignOffsetX,
+ displayRect.y() - alignOffsetY,
+ rotaryImg->width(), rotaryImg->height());
+ scene()->setSceneRect(0, 0, width(), height());
+
+ createItems();
+}
+
+/* override */
+void RotaryView::resizeEvent(QResizeEvent *event)
+{
+ qDebug() << "resize rotary view :" << size();
+
+ /* scaling */
+ const qreal sx = win->getUIState()->getScaleFactor();
+ const qreal sy = win->getUIState()->getScaleFactor();
+ setTransform(QTransform(sx, 0, 0, 0, sy, 0, 0, 0, 1));
+
+ /* masking */
+ setMask(win->uiInfo->getMainForm()->getRotaryImage()->mask());
+
+ QGraphicsView::resizeEvent(event);
+}
+
+/* override */
+void RotaryView::setMask(const QRegion ®ion)
+{
+ if (region.isEmpty() == false) {
+ QWidget::setMask(region);
+ }
+}
+
+int RotaryView::getAngleFromVector(QPoint pos)
+{
+ return (int)(qAtan2(
+ pos.y() - (height() / 2), pos.x() - (width() / 2)) *
+ float(180 / M_PI) /* radians to degress */);
+}
+
+/* override */
+void RotaryView::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ grabPos = event->pos();
+ grabAngle = getAngleFromVector(grabPos);
+ }
+
+ QGraphicsView::mousePressEvent(event);
+}
+
+/* override */
+void RotaryView::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ grabPos = QPoint(-1, -1);
+ grabAngle = 0;
+ }
+
+ QGraphicsView::mouseReleaseEvent(event);
+}
+
+/* override */
+void RotaryView::mouseMoveEvent(QMouseEvent *event)
+{
+ if (grabPos != QPoint(-1, -1)) {
+ const int moveAngle = getAngleFromVector(event->pos());
+
+ int deltaAngle = moveAngle - grabAngle;
+ if (deltaAngle < -180) {
+ deltaAngle += 360; /* 359 -> 0 */
+ } else if (deltaAngle > 180) {
+ deltaAngle -= 360; /* 0 -> 359 */
+ }
+ qDebug() << "rotary delta :" << deltaAngle;
+
+ rotaryDegree += deltaAngle;
+
+ /* TODO: too many heavy calls over here
+ move to thread or paintEvent handler */
+ rotaryItem->setRotation(rotaryDegree);
+
+ grabAngle = moveAngle;
+ }
+
+ QGraphicsView::mouseMoveEvent(event);
+}
+
+RotaryView::~RotaryView()
+{
+ qDebug("destroy rotary view");
+
+ scene()->clear();
+}
--- /dev/null
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef ROTARYVIEW_H
+#define ROTARYVIEW_H
+
+#include <QGraphicsView>
+
+class MainWindow;
+
+class RotaryView : public QGraphicsView
+{
+public:
+ RotaryView(QWidget *parent);
+ ~RotaryView();
+
+ void update();
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+ void setMask(const QRegion ®ion);
+
+ void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+
+private:
+ void createItems();
+ int getAngleFromVector(QPoint pos);
+
+ MainWindow *win;
+ QPixmap *rotaryImg;
+ QGraphicsPixmapItem *rotaryItem;
+
+ QPoint grabPos;
+ int grabAngle;
+ int rotaryDegree; /* absolute */
+
+};
+
+#endif // ROTARYVIEW_H