/************************************************************************ Copyright (c) 2005-2012 by Juphoon System Software Co., Ltd. All rights reserved. This software is confidential and proprietary to Juphoon System Software Co., Ltd.. No part of this software may be reproduced, stored, transmitted, disclosed or used in any form or by any means other than as expressly provided by the written license agreement between JusTel and its licensee. THIS SOFTWARE IS PROVIDED BY JusTel "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JusTel BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Juphoon System Software Co., Ltd. ************************************************************************/ /************************************************* File name : rmetrodlg.h Module : UI Widget Author : vic.ren Created on : 2012-09-13 Description : The base effect widget Modify History: 1. Date: Author: Modification: 2012-09-13 Vic Ren upgrade *************************************************/ #include "JusCallPch.h" RMetroDlg::RMetroDlg(QWidget *parent) : RWidget(parent) , m_pLabelTitle(ZNULL) , m_pBtnMin(ZNULL) , m_pBtnMax(ZNULL) , m_pBtnClose(ZNULL) , m_pBtnAccept(ZNULL) , m_pBtnReject(ZNULL) , m_bDragEnabled(false) , m_bHasBoder(false) , m_bHasTitle(false) { } void RMetroDlg::showEvent(QShowEvent *event) { if (!event) return; QWidget::showEvent(event); } void RMetroDlg::closeEvent(QCloseEvent *event) { if (!event) return; QWidget::closeEvent(event); } void RMetroDlg::hideEvent(QHideEvent *event) { if (!event) return; QWidget::hideEvent(event); } void RMetroDlg::resizeEvent(QResizeEvent *event) { if (!event) return; QWidget::resizeEvent(event); int nBtnX = width(); int nSpacing = 20; if (m_pLabelTitle) m_pLabelTitle->move(BORDER_LEFT + 20, BORDER_TOP + 15); if (m_pBtnReject) { nBtnX = nBtnX - nSpacing - m_pBtnReject->width(); m_pBtnReject->move(nBtnX, height() - nSpacing - m_pBtnReject->height()); } if (m_pBtnAccept) { if (m_pBtnReject) nBtnX = nBtnX - 10 - m_pBtnAccept->width(); else nBtnX = nBtnX - nSpacing - m_pBtnAccept->width(); m_pBtnAccept->move(nBtnX, height() - nSpacing - m_pBtnAccept->height()); } nBtnX = width(); if (m_pBtnClose) { nBtnX -= 20; m_pBtnClose->move(nBtnX - 1, 1); } if (m_pBtnMax) { nBtnX -= 20; m_pBtnMax->move(nBtnX - 1, 1); } if (m_pBtnMin) { nBtnX -= 20; m_pBtnMin->move(nBtnX - 1, 1); } } void RMetroDlg::paintEvent(QPaintEvent * event) { if (!event) return; QPainter painter(this); painter.setRenderHint(QPainter::HighQualityAntialiasing); if (m_bHasBoder) { painter.fillRect(rect(), RStyle::boderColor()); painter.fillRect(QRect(1, 1, width() - 2, height() - 2), RStyle::backgroundColor()); } RWidget::paintEvent(event); } void RMetroDlg::mousePressEvent(QMouseEvent *event) { if (!event) return; QWidget::mousePressEvent(event); m_ptLastPoint = event->globalPos(); } void RMetroDlg::mouseReleaseEvent(QMouseEvent * event) { if (!event) return; QWidget::mouseReleaseEvent(event); m_ptLastPoint = QPoint(0, 0); } void RMetroDlg::mouseMoveEvent(QMouseEvent *event) { if (!event) return; QWidget::mouseMoveEvent(event); if (m_ptLastPoint == QPoint(0, 0)) return; if (m_bDragEnabled) { QPoint ptNewPoint = event->globalPos(); if (event->buttons() == Qt::LeftButton) { QPoint ptLeftUpPoint = mapToParent(ptNewPoint - m_ptLastPoint); move(ptLeftUpPoint); m_ptLastPoint = ptNewPoint; } } } void RMetroDlg::addTitle(const QString & qsTitle, int nType) { if (!qsTitle.isEmpty()) { m_bHasTitle = true; m_pLabelTitle = new QLabel(this); m_pLabelTitle->setFixedHeight(30); m_pLabelTitle->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_pLabelTitle->setFont(RStyle::fontSize(21)); QString qsTmp = qsTitle.toUpper(); m_pLabelTitle->setText(qsTmp); m_pLabelTitle->show(); } if (nType & EN_UI_DLG_BTN_CLOSE) { m_pBtnClose = new RRightTopBtn(this, ":/images/ic_btn_close.png"); m_pBtnClose->resize(TOPSPACE, TOPSPACE); connect(m_pBtnClose, SIGNAL(clicked()), SIGNAL(signalClickedBtnClose())); } if (nType & EN_UI_DLG_BTN_MAX) { m_pBtnMax = new RRightTopBtn(this, ":/images/ic_btn_close.png"); m_pBtnMax->resize(TOPSPACE, TOPSPACE); connect(m_pBtnMax, SIGNAL(clicked()), SIGNAL(signalClickedBtnMax())); } if (nType & EN_UI_DLG_BTN_MIN) { m_pBtnMin = new RRightTopBtn(this, ":/images/ic_btn_min.png"); m_pBtnMin->resize(TOPSPACE, TOPSPACE); connect(m_pBtnMin, SIGNAL(clicked()), SIGNAL(signalClickedBtnMin())); } } void RMetroDlg::raiseTitle() { if (m_pBtnClose) m_pBtnClose->raise(); if (m_pBtnMax) m_pBtnMax->raise(); if (m_pBtnMin) m_pBtnMin->raise(); } void RMetroDlg::addButton(const QString & text, ButtonRole role) { if (role == RMetroDlg::AcceptRole) { if (!m_pBtnAccept) { m_pBtnAccept = new RMetroBtn(this); connect(m_pBtnAccept, SIGNAL(clicked()), SIGNAL(signalClickedBtnAccept())); } m_pBtnAccept->setText(text); } else { if (!m_pBtnReject) { m_pBtnReject = new RMetroBtn(this); m_pBtnReject->setButtonNegtive(); connect(m_pBtnReject, SIGNAL(clicked()), SIGNAL(signalClickedBtnReject())); } m_pBtnReject->setText(text); } } void RMetroDlg::addBoder() { m_bHasBoder = true; } void RMetroDlg::setDragEnabled(bool bEnabled) { m_bDragEnabled = bEnabled; } void RMetroDlg::updateStyle() { #if 0 if (m_pBtnAccept) m_pBtnAccept->updateStyle(); if (m_pBtnReject) m_pBtnReject->updateStyle(); #endif update(); } void RMetroDlg::setTitleVisible(bool bVisible) { if (m_pBtnClose) m_pBtnClose->setVisible(bVisible); if (m_pBtnMax) m_pBtnMax->setVisible(bVisible); if (m_pBtnMin) m_pBtnMin->setVisible(bVisible); }