2018-02-09 15:54:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
|
|
|
*
|
|
|
|
* 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; version 3.
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "selectwidget.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2018-02-11 19:02:25 +08:00
|
|
|
#include <QGraphicsDropShadowEffect>
|
2018-02-09 15:54:05 +08:00
|
|
|
|
2018-02-10 14:40:50 +08:00
|
|
|
SelectWidget::SelectWidget(CleanerModuleID id, const QString &title, bool needMin, QWidget *parent)
|
2018-02-09 15:54:05 +08:00
|
|
|
: QDialog(parent)
|
|
|
|
, m_mousePressed(false)
|
2018-02-10 14:40:50 +08:00
|
|
|
, m_id(id)
|
2018-02-09 15:54:05 +08:00
|
|
|
{
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint);
|
|
|
|
this->setFixedSize(464, 500);
|
|
|
|
|
2018-02-11 22:38:52 +08:00
|
|
|
QWidget *containerWidget = new QWidget(this);
|
|
|
|
m_mainLayout = new QVBoxLayout(containerWidget);
|
|
|
|
m_mainLayout->setContentsMargins(0,0,0,0);
|
2018-02-09 15:54:05 +08:00
|
|
|
m_mainLayout->setSpacing(0);
|
|
|
|
m_mainLayout->setMargin(0);
|
2018-02-10 14:40:50 +08:00
|
|
|
m_titleBar = new MyTitleBar(title, needMin, this);
|
2018-02-11 22:38:52 +08:00
|
|
|
m_titleBar->setFixedSize(this->width(), TITLE_BAR_HEIGHT);
|
2018-02-10 14:40:50 +08:00
|
|
|
m_listWidget = new SelectListWidget(false, this);
|
2018-02-11 22:38:52 +08:00
|
|
|
m_listWidget->setFixedSize(this->width(), this->height() - TITLE_BAR_HEIGHT);
|
2018-02-09 15:54:05 +08:00
|
|
|
m_mainLayout->addWidget(m_titleBar);
|
|
|
|
m_mainLayout->addWidget(m_listWidget);
|
|
|
|
|
2018-02-10 14:40:50 +08:00
|
|
|
connect(m_titleBar, SIGNAL(minSignal()), this, SLOT(hide()));
|
|
|
|
connect(m_titleBar, SIGNAL(closeSignal()), this, SLOT(onClose()));
|
2018-02-09 15:54:05 +08:00
|
|
|
connect(m_listWidget, SIGNAL(notifyMainCheckBox(int)), this, SIGNAL(notifyMainCheckBox(int)));
|
|
|
|
|
2018-02-11 19:02:25 +08:00
|
|
|
// //边框阴影效果
|
|
|
|
// QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
|
|
|
|
// shadow_effect->setBlurRadius(5);
|
|
|
|
// shadow_effect->setColor(QColor(0, 0, 0, 127));
|
|
|
|
// shadow_effect->setOffset(2, 4);
|
|
|
|
// this->setGraphicsEffect(shadow_effect);
|
|
|
|
|
2018-02-09 15:54:05 +08:00
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
|
|
this->move((desktop->width() - this->width())/2, (desktop->height() - this->height())/3);
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectWidget::~SelectWidget()
|
|
|
|
{
|
2018-02-11 22:38:52 +08:00
|
|
|
delete m_titleBar;
|
|
|
|
delete m_listWidget;
|
|
|
|
delete m_mainLayout;
|
2018-02-09 15:54:05 +08:00
|
|
|
}
|
|
|
|
|
2018-02-10 14:40:50 +08:00
|
|
|
void SelectWidget::onClose()
|
|
|
|
{
|
|
|
|
emit refreshSelectedItems(m_id, m_listWidget->getSelectedItems());
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:54:05 +08:00
|
|
|
void SelectWidget::loadData(const QString &title, const QStringList &cachelist)
|
|
|
|
{
|
2018-02-11 22:38:52 +08:00
|
|
|
m_listWidget->loadListItems(title, cachelist, this->width() - 2*ITEM_LEFT_RIGHT_PADDING);
|
2018-02-09 15:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelectWidget::moveCenter()
|
|
|
|
{
|
|
|
|
/*QPoint pos = QCursor::pos();
|
|
|
|
QRect primaryGeometry;
|
|
|
|
for (QScreen *screen : qApp->screens()) {
|
|
|
|
if (screen->geometry().contains(pos)) {
|
|
|
|
primaryGeometry = screen->geometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (primaryGeometry.isEmpty()) {
|
|
|
|
primaryGeometry = qApp->primaryScreen()->geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->move(primaryGeometry.x() + (primaryGeometry.width() - this->width())/2,
|
|
|
|
primaryGeometry.y() + (primaryGeometry.height() - this->height())/2);
|
|
|
|
this->show();
|
|
|
|
this->raise();*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SelectWidget::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
this->m_dragPosition = event->globalPos() - frameGeometry().topLeft();
|
|
|
|
this->m_mousePressed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectWidget::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
this->m_mousePressed = false;
|
|
|
|
setWindowOpacity(1);
|
|
|
|
|
|
|
|
QDialog::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectWidget::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (this->m_mousePressed) {
|
|
|
|
move(event->globalPos() - this->m_dragPosition);
|
|
|
|
setWindowOpacity(0.9);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::mouseMoveEvent(event);
|
|
|
|
}
|