2012-09-16 20:19:10 +02:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2017-01-27 13:42:05 +01:00
|
|
|
* Copyright (C) 2012-2014 Franz Fellner <alpine.art.de@googlemail.com>
|
|
|
|
* Copyright (C) 2012-2017 David Rosca <nowrep@gmail.com>
|
2012-09-16 20:19:10 +02:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2012-09-15 17:54:12 +02:00
|
|
|
#include "locationbarpopup.h"
|
|
|
|
|
2013-02-10 12:28:53 +01:00
|
|
|
#include <QLayout>
|
|
|
|
|
2012-09-15 17:54:12 +02:00
|
|
|
LocationBarPopup::LocationBarPopup(QWidget* parent)
|
|
|
|
: QFrame(parent, Qt::Popup)
|
|
|
|
, m_alignment(Qt::AlignRight)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2017-01-27 13:42:05 +01:00
|
|
|
setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
|
2012-09-15 17:54:12 +02:00
|
|
|
setLineWidth(1);
|
|
|
|
setMidLineWidth(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarPopup::showAt(QWidget* parent)
|
|
|
|
{
|
2016-01-25 14:21:17 +01:00
|
|
|
if (!parent || !parent->parentWidget())
|
2013-02-10 12:28:53 +01:00
|
|
|
return;
|
2016-01-25 14:21:17 +01:00
|
|
|
|
|
|
|
parent = parent->parentWidget();
|
2013-02-10 12:28:53 +01:00
|
|
|
|
|
|
|
// Calculate sizes before showing
|
2012-09-15 17:54:12 +02:00
|
|
|
layout()->invalidate();
|
|
|
|
layout()->activate();
|
|
|
|
|
|
|
|
QPoint p = parent->mapToGlobal(QPoint(0, 0));
|
2012-09-16 20:19:10 +02:00
|
|
|
|
2012-09-15 17:54:12 +02:00
|
|
|
if (m_alignment == Qt::AlignRight) {
|
|
|
|
p.setX(p.x() + parent->width() - width());
|
|
|
|
}
|
2012-09-16 20:19:10 +02:00
|
|
|
|
2012-09-15 17:54:12 +02:00
|
|
|
p.setY(p.y() + parent->height());
|
|
|
|
move(p);
|
|
|
|
|
2012-09-16 20:19:10 +02:00
|
|
|
QFrame::show();
|
2012-09-15 17:54:12 +02:00
|
|
|
}
|
2013-02-10 12:28:53 +01:00
|
|
|
|
|
|
|
void LocationBarPopup::setPopupAlignment(Qt::Alignment alignment)
|
|
|
|
{
|
|
|
|
m_alignment = alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment LocationBarPopup::popupAlignment() const
|
|
|
|
{
|
|
|
|
return m_alignment;
|
|
|
|
}
|