summaryrefslogtreecommitdiff
path: root/tizen/src/ui/generalskinview.cpp
blob: 8817588563bfd78b27e67cc9038695972b0f466a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Qt UI
 *
 * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact:
 * Jihye Kim <jihye424.kim@samsung.com>
 * SeokYeon Hwang <syeon.hwang@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 "generalskinview.h"
#include "mainwindow.h"

GeneralSkinView::GeneralSkinView(QGraphicsScene *scene, QWidget *parent)
    : MainView(scene, parent)
{
}

GeneralSkinView::~GeneralSkinView()
{
    qDebug("destroy general skin view");
}

/* override */
void GeneralSkinView::resizeEvent(QResizeEvent *event)
{
    qDebug() << "resize general skin view:" << size();
    SkinView::resizeEvent(event);
}

/* override */
void GeneralSkinView::mousePressEvent(QMouseEvent *event)
{
    SkinView::mousePressEvent(event);

    if (event->button() == Qt::LeftButton) {
        grabWindow(event->globalPos());
    }
}

/* override */
void GeneralSkinView::mouseReleaseEvent(QMouseEvent *event)
{
    SkinView::mouseReleaseEvent(event);

    if (event->button() == Qt::LeftButton) {
        releaseWindow();
    }
}

/* override */
void GeneralSkinView::mouseMoveEvent(QMouseEvent *event)
{
    SkinView::mouseMoveEvent(event);

    if (isGrabWindow() == true) {
        win->move(grabWinPos + (event->globalPos() - grabPos));
    }
}

void GeneralSkinView::createItems()
{
    qDebug() << "create items for general skin view";

    QBrush backBrush(QColor(244, 244, 244));
    QPen linePen(QColor(205, 205, 205), 1, Qt::SolidLine);
    QSize size = win->getUiInfo()->getMainSize();
    scene()->addRect(BORDER_SIZE, BORDER_SIZE, size.width() - BORDER_SIZE * 2, HEADER_HEIGHT, QPen(Qt::NoPen), backBrush);
    scene()->addLine(BORDER_SIZE, HEADER_HEIGHT + BORDER_SIZE, size.width() - BORDER_SIZE, HEADER_HEIGHT + BORDER_SIZE, linePen);

    if (BORDER_SIZE > 0) {
        QPen boaderPen(win->getUiInfo()->getVMColor(), BORDER_SIZE * 2, Qt::SolidLine);
        scene()->addRect(0, 0, size.width(), size.height(), boaderPen);
    }

    QGraphicsTextItem *title = new QGraphicsTextItem(win->getUiInfo()->getVmName());
    title->setDefaultTextColor(QColor(88, 88, 88));
    scene()->addItem(title);
    QRectF rect = title->boundingRect();
    int y = (HEADER_HEIGHT - rect.height()) / 2;
    title->setPos(BORDER_SIZE + 5, BORDER_SIZE + y);
}

QSize GeneralSkinView::getMainSize()
{
    QSize size = win->getUiInfo()->getMainForm()->
            skinImg[LayoutForm::normal].size() * win->getUiInfo()->getUiState()->getScaleFactor();

    size.setWidth(size.width() + BORDER_SIZE * 2);
    size.setHeight(size.height() + HEADER_HEIGHT + BORDER_SIZE * 2);

    return size;
}

QRegion GeneralSkinView::getMainRegion()
{
    QImage *mainImage = &(win->getUiInfo()->getMainForm()->skinImg[LayoutForm::normal]);
    QImage regionImage = mainImage->scaled(
            mainImage->width() * win->getUiInfo()->getUiState()->getScaleFactor() + BORDER_SIZE * 2,
            mainImage->height() * win->getUiInfo()->getUiState()->getScaleFactor()
                                + HEADER_HEIGHT + BORDER_SIZE * 2).createAlphaMask();

    return QRegion(QBitmap::fromImage(regionImage));
}