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 126 127
|
/*
* Kylin-video
*
* Copyright (C) 2021, Tianjin KYLIN Information Technology Co., Ltd.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
* Authors: Liu Cong <liucong1@kylinos.cn>
*
*/
#include "messagebox.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
namespace KylinUI {
MessageBox::MessageBox(QString title, QString text, QWidget *parent, MessageType type) :
Dialog(parent)
{
msg_type = type;
initLayout();
setData(title, text);
}
MessageBox::~MessageBox()
{
delete lab_titleIcon;
delete lab_title;
delete lab_text;
delete lab_textIcon;
delete btn_ok;
delete box_hb;
delete box_hm;
delete box_ht;
delete box_v;
}
void MessageBox::setData(QString title, QString text)
{
QIcon icMsg, icTitle = QIcon::fromTheme("kylin-video");
switch (msg_type) {
case INFORMATION:
icMsg = QIcon::fromTheme("ukui-dialog-information");
btn_cancel->hide();
break;
case QUESTION:
icMsg = QIcon::fromTheme("ukui-dialog-help");
break;
case WARNING:
icMsg = QIcon::fromTheme("ukui-dialog-warning");
btn_cancel->hide();
break;
case ABOUT:
icMsg = QIcon::fromTheme("about");
btn_cancel->hide();
break;
default:
break;
}
lab_title->setText(title);
lab_titleIcon->setPixmap(icTitle.pixmap(lab_titleIcon->size()));
lab_text->setText(text);
lab_textIcon->setPixmap(icMsg.pixmap(lab_textIcon->size()));
}
void MessageBox::initLayout()
{
setFixedSize(WIDGET_WIDTH, WIDGET_HEIGHT);
box_ht = new QHBoxLayout;
box_hm = new QHBoxLayout;
box_hb = new QHBoxLayout;
box_v = new QVBoxLayout(this);
box_v->addLayout(box_ht);
box_v->addSpacing(10);
box_v->addLayout(box_hm);
box_v->addStretch();
box_v->addLayout(box_hb);
lab_titleIcon = new QLabel;
lab_titleIcon->setFixedSize(TITLE_ICON_WIDTH, TITLE_ICON_WIDTH);
lab_title = new QLabel;
box_ht->addWidget(lab_titleIcon);
box_ht->addWidget(lab_title);
box_ht->addStretch();
lab_text = new QLabel;
lab_textIcon = new QLabel;
lab_textIcon->setFixedSize(TEXT_ICON_WIDTH, TEXT_ICON_WIDTH);
box_hm->addSpacing(24);
box_hm->addWidget(lab_textIcon);
box_hm->addWidget(lab_text);
box_hm->addStretch();
btn_cancel = new QPushButton;
btn_cancel->setFixedSize(80, 30);
btn_cancel->setText(tr("Cancle"));
btn_ok = new QPushButton;
btn_ok->setFixedSize(80, 30);
btn_ok->setText(tr("Ok"));
connect(btn_cancel, &QPushButton::clicked, this, &MessageBox::reject);
connect(btn_ok, &QPushButton::clicked, this, &MessageBox::accept);
box_hb->addStretch();
box_hb->addWidget(btn_cancel);
box_hb->addWidget(btn_ok);
box_hb->setContentsMargins(0, 0, 24, 16);
}
}
|