2015-02-17 18:02:47 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vwidgetpopup.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 16 2, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-02-17 18:02:47 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-02-17 18:02:47 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina 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.
|
|
|
|
**
|
|
|
|
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vwidgetpopup.h"
|
|
|
|
|
2018-05-27 11:08:02 +02:00
|
|
|
#include <QScreen>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QFont>
|
2018-05-27 11:08:02 +02:00
|
|
|
#include <QGuiApplication>
|
2015-09-16 10:03:15 +02:00
|
|
|
#include <QLabel>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <Qt>
|
2015-09-16 10:03:15 +02:00
|
|
|
|
|
|
|
#include "../vmisc/def.h"
|
2015-02-17 18:02:47 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VWidgetPopup::VWidgetPopup(QWidget *parent)
|
|
|
|
:QFrame(parent, Qt::Popup), mWidget(nullptr), mOwn(true), mOldParent(nullptr), lifeTime(-1)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_WindowPropagation);
|
|
|
|
|
|
|
|
if (parentWidget() == nullptr)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLayout(new QVBoxLayout());
|
|
|
|
layout()->setContentsMargins(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VWidgetPopup::SetWidget(QWidget *widget, bool own)
|
|
|
|
{
|
|
|
|
if (mWidget)
|
|
|
|
{
|
|
|
|
layout()->removeWidget(mWidget);
|
|
|
|
|
|
|
|
if (mOwn)
|
|
|
|
{
|
2017-07-05 18:35:34 +02:00
|
|
|
mWidget->setParent(nullptr);
|
2015-02-17 18:02:47 +01:00
|
|
|
delete mWidget;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mWidget->setParent(mOldParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mWidget = widget;
|
|
|
|
mOwn = own;
|
2017-07-05 18:35:34 +02:00
|
|
|
mOldParent = nullptr;
|
2015-02-17 18:02:47 +01:00
|
|
|
|
|
|
|
if (mWidget)
|
|
|
|
{
|
|
|
|
mOldParent = mWidget->parentWidget();
|
|
|
|
mWidget->setParent(this);
|
|
|
|
layout()->addWidget(mWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 10:03:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VWidgetPopup::PopupMessage(QWidget *w, const QString &msg)
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(w != nullptr)
|
2015-09-16 10:03:15 +02:00
|
|
|
|
2017-07-24 19:00:59 +02:00
|
|
|
VWidgetPopup *popup = new VWidgetPopup(w);
|
2015-09-16 10:03:15 +02:00
|
|
|
QLabel *label = new QLabel(msg);
|
|
|
|
QFont f = label->font();
|
|
|
|
f.setBold(true);
|
|
|
|
f.setPixelSize(16);
|
|
|
|
label->setFont(f);
|
|
|
|
popup->SetWidget(label);
|
|
|
|
popup->SetLifeTime(2000);
|
|
|
|
popup->Show(w->frameGeometry().center());
|
|
|
|
}
|
|
|
|
|
2015-02-17 18:02:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VWidgetPopup::Show(QPoint coord)
|
|
|
|
{
|
|
|
|
// important to do this before following adjustments!
|
|
|
|
QFrame::show();
|
|
|
|
|
2018-05-27 11:08:02 +02:00
|
|
|
const QRect screen(QGuiApplication::primaryScreen()->availableGeometry());
|
2015-02-17 18:02:47 +01:00
|
|
|
coord.setX(coord.x() - width()/2);
|
|
|
|
|
|
|
|
if (coord.x() < screen.x())
|
|
|
|
{
|
|
|
|
coord.setX(screen.x());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coord.y() < screen.y())
|
|
|
|
{
|
|
|
|
coord.setY(screen.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coord.x() > (screen.right()-width()))
|
|
|
|
{
|
|
|
|
coord.setX(screen.right()-width());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coord.y() > (screen.bottom()-height()))
|
|
|
|
{
|
|
|
|
coord.setY(screen.bottom()-height());
|
|
|
|
}
|
|
|
|
move(coord);
|
|
|
|
|
|
|
|
if (lifeTime > 0)
|
|
|
|
{
|
2018-04-18 10:15:53 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
|
|
|
QTimer::singleShot(lifeTime, this, &QWidget::close);
|
|
|
|
#else
|
2015-02-17 18:02:47 +01:00
|
|
|
QTimer::singleShot(lifeTime, this, SLOT(close()));
|
2018-04-18 10:15:53 +02:00
|
|
|
#endif
|
2015-02-17 18:02:47 +01:00
|
|
|
}
|
|
|
|
}
|