2015-02-17 18:02:47 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vwidgetpopup.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 16 2, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** 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"
|
|
|
|
|
|
|
|
#include <QDesktopWidget>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QFont>
|
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
|
|
|
|
|
|
|
VWidgetPopup *popup = new VWidgetPopup();
|
|
|
|
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();
|
|
|
|
|
|
|
|
const QRect screen(QDesktopWidget().availableGeometry());
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
QTimer::singleShot(lifeTime, this, SLOT(close()));
|
|
|
|
}
|
|
|
|
}
|