File indexing completed on 2024-05-19 04:58:51

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2012-2014 Franz Fellner <alpine.art.de@googlemail.com>
0004 * Copyright (C) 2012-2017 David Rosca <nowrep@gmail.com>
0005 *
0006 * This program is free software: you can redistribute it and/or modify
0007 * it under the terms of the GNU General Public License as published by
0008 * the Free Software Foundation, either version 3 of the License, or
0009 * (at your option) any later version.
0010 *
0011 * This program is distributed in the hope that it will be useful,
0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 * GNU General Public License for more details.
0015 *
0016 * You should have received a copy of the GNU General Public License
0017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 * ============================================================ */
0019 #include "locationbarpopup.h"
0020 
0021 #include <QLayout>
0022 
0023 LocationBarPopup::LocationBarPopup(QWidget* parent)
0024     : QFrame(parent, Qt::Popup)
0025     , m_alignment(Qt::AlignRight)
0026 {
0027     setAttribute(Qt::WA_DeleteOnClose);
0028     setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0029     setLineWidth(1);
0030     setMidLineWidth(2);
0031 }
0032 
0033 void LocationBarPopup::showAt(QWidget* parent)
0034 {
0035     if (!parent || !parent->parentWidget())
0036         return;
0037 
0038     parent = parent->parentWidget();
0039 
0040     // Calculate sizes before showing
0041     layout()->invalidate();
0042     layout()->activate();
0043 
0044     QPoint p = parent->mapToGlobal(QPoint(0, 0));
0045 
0046     if (m_alignment == Qt::AlignRight) {
0047         p.setX(p.x() + parent->width() - width());
0048     }
0049 
0050     p.setY(p.y() + parent->height());
0051     move(p);
0052 
0053     QFrame::show();
0054 }
0055 
0056 void LocationBarPopup::setPopupAlignment(Qt::Alignment alignment)
0057 {
0058     m_alignment = alignment;
0059 }
0060 
0061 Qt::Alignment LocationBarPopup::popupAlignment() const
0062 {
0063     return m_alignment;
0064 }