/* * Qt UI * * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim * Sangho Park * * 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 #include #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) { drawSkin(centerPatch, degree, separators); } void SkinPainter::drawSkin(QSize center, int degree, QList separators) { qDebug() << "draw skin surface"; QRect centeralRect(0, 0, center.width(), center.height()); QPixmap image(center.width(), center.height()); image.fill(Qt::black); 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))); this->centeralRect = QRect(centeralRect.topLeft(), 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(); } QRect SkinPainter::getCenteralRect() { return centeralRect; } SkinPainter::~SkinPainter() { qDebug("destroy skin painter"); if (skin != NULL) { delete skin; } }