/* * Qt UI * * Copyright (C) 2014 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 "uiinformation.h" #include "resource/ui_strings.h" UiInformation::UiInformation() : basePort(0) { this->resolution = QSize(0, 0); this->vmDataPath = "./"; this->skinPath = "./"; } void UiInformation::setVmName(QString name) { vmName = name; } QString UiInformation::getVmName() { return vmName; } void UiInformation::setResolution(QSize size) { resolution = size; } QSize UiInformation::getResolution() { return resolution; } void UiInformation::setBasePort(int port) { basePort = port; } int UiInformation::getBasePort() { return basePort; } void UiInformation::setVmDataPath(QString path) { vmDataPath = path; } QString UiInformation::getVmDataPath() { return vmDataPath; } void UiInformation::setSkinPath(QString path) { skinPath = path; } QString UiInformation::getSkinPath() { return skinPath; } void UiInformation::setSkinName(QString name) { skinName = name; } QString UiInformation::getSkinName() { return skinName; } QList &UiInformation::getMainFormList() { return mainFormList; } QList &UiInformation::getConFormList() { return conFormList; } QList &UiInformation::getMenuList() { return menuList; } UIState *UiInformation::getUiState() { return &uiState; } QColor UiInformation::getVMColor() { if (basePort <= 0) { qWarning() << "invalid base port:" << basePort; return QColor(255, 0, 0); } switch((basePort / 10) % 10) { case 0: break; case 1: return QColor(246, 226, 0); case 2: return QColor(0, 246, 12); case 3: return QColor(168, 43, 255); case 4: return QColor(246, 110, 0); case 5: return QColor(245, 48, 233); case 6: return QColor(94, 73, 255); case 7: return QColor(179, 246, 0); case 8: return QColor(245, 48, 48); case 9: return QColor(29, 223, 221); } return QColor(0, 174, 239); } /* form */ MainForm *UiInformation::getMainForm() { int index = uiState.getMainFormIndex(); if (index > (mainFormList.count() - 1) || index < 0) { qWarning("invalid form found"); uiState.setMainFormIndex(0); index = uiState.getMainFormIndex(); } MainForm *mainForm = mainFormList.at(index); if (mainForm == NULL) { qFatal(MSG_INVALID_MAIN_FORM); } return mainForm; } DisplayType *UiInformation::getMainFormDpyType() { return getMainForm()->getDpyType(); } ControllerForm *UiInformation::getConForm() { int index = uiState.getConState()->getConFormIndex(); if (index > (conFormList.count() - 1) || index < 0) { qWarning("invalid form found"); return NULL; } return conFormList.at(index); } /* size */ QSize UiInformation::getMainSize() { return getMainForm()-> skinImg[LayoutForm::normal].size() * uiState.getScaleFactor(); } QSize UiInformation::getConSize() { ControllerForm *conForm = getConForm(); if (conForm == NULL) { qWarning("controller form is null"); return QSize(0, 0); } return conForm->skinImg[LayoutForm::normal].size(); } QSize UiInformation::getUiSize() { QSize uiSize = getMainSize(); /* docking controller */ if (uiState.getConState()->getDockingCon() != NULL) { QSize conSize = getConSize(); uiSize.setWidth(uiSize.width() + conSize.width()); uiSize.setHeight(qMax(uiSize.height(), conSize.height())); } return uiSize; } /* region */ QRegion UiInformation::getMainRegion() { QImage *mainImage = &(getMainForm()->skinImg[LayoutForm::normal]); QImage regionImage = mainImage->scaled( mainImage->width() * uiState.getScaleFactor(), mainImage->height() * uiState.getScaleFactor()).createAlphaMask(); return QRegion(QBitmap::fromImage(regionImage)); } QRegion UiInformation::getConRegion() { ControllerForm *conForm = getConForm(); if (conForm == NULL) { qWarning("controller form is null"); return QRegion(0, 0, 0, 0); } QImage *conImage = &(conForm->skinImg[LayoutForm::normal]); return QRegion(QBitmap::fromImage(conImage->createAlphaMask())); } QRegion UiInformation::getUiRegion() { QRegion uiRegion = getMainRegion(); /* docking controller */ DockingController *con = uiState.getConState()->getDockingCon(); if (con != NULL) { QRegion conRegion = getConRegion(); int vShift = 0; if (getMainSize().height() > getConSize().height()) { if (con->getDockPos() & Qt::AlignCenter) { vShift = (getMainSize().height() - getConSize().height()) / 2; } else if (con->getDockPos() & Qt::AlignBottom) { vShift = getMainSize().height() - getConSize().height(); } } conRegion.translate(getMainSize().width() + 1, vShift); uiRegion = uiRegion.united(conRegion); } return uiRegion; } QRegion UiInformation::getMainKeyRegion( QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) { QRegion baseRegion = base->mask().subtracted(QRect( keyRect.topLeft() * uiState.getScaleFactor(), keyRect.size() * uiState.getScaleFactor())); QImage keyImage = getMainForm()->skinImg[type].copy(keyRect); QImage regionImage = keyImage.scaled( keyImage.width() * uiState.getScaleFactor(), keyImage.height() * uiState.getScaleFactor()).createAlphaMask(); QRegion keyRegion(QBitmap::fromImage(regionImage)); keyRegion.translate(keyRect.topLeft() * uiState.getScaleFactor()); return baseRegion.united(keyRegion); } QRegion UiInformation::getConKeyRegion( QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) { if (getConForm() == NULL) { qWarning("controller form is null"); return QRegion(); } if (getConForm()->skinImg[type].size() == QSize(0, 0)) { qWarning("invalid controller image"); return QRegion(); } QRegion baseRegion; QRegion keyRegion; if (uiState.getConState()->getDockingCon() != NULL) { /* docking controller */ const int shiftW = getMainSize().width(); baseRegion = getUiRegion().subtracted(QRect( keyRect.x() + shiftW, keyRect.y(), keyRect.width(), keyRect.height())); QImage keyImage = getConForm()->skinImg[type].copy(keyRect); keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask())); keyRegion.translate(keyRect.left() + shiftW, keyRect.top()); } else { baseRegion = base->mask().subtracted(QRect( keyRect.x(), keyRect.y(), keyRect.width(), keyRect.height())); QImage keyImage = getConForm()->skinImg[type].copy(keyRect); keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask())); keyRegion.translate(keyRect.left(), keyRect.top()); } return baseRegion.united(keyRegion); } UiInformation::~UiInformation() { qDebug("destroy UI info"); for (int i = 0; i < mainFormList.count(); i++) { delete mainFormList.at(i); } mainFormList.clear(); for (int i = 0; i < conFormList.count(); i++) { delete conFormList.at(i); } conFormList.clear(); for (int i = 0; i < menuList.count(); i++) { delete menuList.at(i); } menuList.clear(); }