/************************************************************************ 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 : rmessagebox.cpp Module : UI Dialog Author : vic.ren Created on : 2012-08-01 Description : The MessageBox dialog Modify History: 1. Date: Author: Modification: *************************************************/ #include "JusCallPch.h" const int LABELWIDTH = 340; RMessageBox::RMessageBox(QWidget *parent, const QString &qsTitle) : QDialog(parent), m_qsTitle(qsTitle), m_pBtnAccept(ZNULL), m_pBtnReject(ZNULL) { setWindowFlags(Qt::FramelessWindowHint); setAutoFillBackground(true); initDlg(); } void RMessageBox::showEvent(QShowEvent *event) { if (!event) return; QDialog::showEvent(event); } void RMessageBox::resizeEvent(QResizeEvent *event) { if (!event) return; QWidget::resizeEvent(event); m_pLabelContent->move(20, 60); if (m_pBtnReject && m_pBtnAccept) { m_pBtnReject->move(width() - 20 - m_pBtnReject->width(), height() - 20 - m_pBtnReject->height()); m_pBtnAccept->move(m_pBtnReject->x() - 20 - m_pBtnReject->width(), height() - 20 - m_pBtnAccept->height()); } else if (m_pBtnReject) { m_pBtnReject->move(width() - 20 - m_pBtnReject->width(), height() - 20 - m_pBtnReject->height()); } else if (m_pBtnAccept) { m_pBtnAccept->move(width() - 20 - m_pBtnAccept->width(), height() - 20 - m_pBtnAccept->height()); } } void RMessageBox::mousePressEvent(QMouseEvent *event) { if (!event) return; QDialog::mousePressEvent(event); m_ptLastPoint = event->globalPos(); } void RMessageBox::mouseReleaseEvent(QMouseEvent * event) { if (!event) return; QDialog::mouseReleaseEvent(event); m_ptLastPoint = QPoint(0, 0); } void RMessageBox::mouseMoveEvent(QMouseEvent *event) { if (!event) return; QDialog::mouseMoveEvent(event); if (m_ptLastPoint == QPoint(0, 0)) return; QPoint ptNewPoint = event->globalPos(); if (event->buttons() == Qt::LeftButton) { QPoint ptLeftUpPoint = mapToParent(ptNewPoint - m_ptLastPoint); move(ptLeftUpPoint); m_ptLastPoint = ptNewPoint; } } void RMessageBox::initDlg() { setWindowTitle(m_qsTitle); m_pTray = new RMetroDlg(this); m_pTray->addTitle(m_qsTitle, EN_UI_DLG_BTN_CLOSE); m_pTray->addBoder(); connect(m_pTray, SIGNAL(signalClickedBtnClose()), SLOT(slotClickedBtnReject())); m_pLabelContent = new QLabel(m_pTray); m_pLabelContent->setFixedWidth(LABELWIDTH); m_pLabelContent->setWordWrap(true); m_pTray->resize(380, 170); resize(380, 170); } void RMessageBox::setText(const QString &qsContent) { m_pLabelContent->setText(qsContent); QFontMetrics fmContent(m_pLabelContent->font()); int nHeight = (fmContent.width(qsContent)/LABELWIDTH + 1) * fmContent.height(); if (nHeight < 40) return; m_pTray->resize(180, nHeight + 130); resize(180, nHeight + 130); } void RMessageBox::addButton(const QString &text, ButtonRole role) { if (role == RMessageBox::AcceptRole) { m_pBtnAccept= new RMetroBtn(m_pTray); connect(m_pBtnAccept, SIGNAL(clicked()), SLOT(slotClickedBtnAccept())); m_pBtnAccept->setText(text); m_pBtnAccept->show(); } else { m_pBtnReject = new RMetroBtn(m_pTray); m_pBtnReject->setButtonNegtive(); connect(m_pBtnReject, SIGNAL(clicked()), SLOT(slotClickedBtnReject())); m_pBtnReject->setText(text); m_pBtnReject->show(); } } void RMessageBox::updateStyle() { } void RMessageBox::slotClickedBtnAccept() { QDialog::done(QDialog::Accepted); } void RMessageBox::slotClickedBtnReject() { QDialog::done(QDialog::Rejected); }