File indexing completed on 2025-01-05 03:56:39
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-01-13 0007 * Description : progress manager 0008 * 0009 * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2004 by David Faure <faure at kde dot org> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "overlaywidget.h" 0017 0018 // KDE includes 0019 0020 #include <QResizeEvent> 0021 #include <QEvent> 0022 0023 namespace Digikam 0024 { 0025 0026 OverlayWidget::OverlayWidget(QWidget* const alignWidget, QWidget* const parent, const QString& name) 0027 : DHBox(parent), 0028 mAlignWidget(nullptr) 0029 { 0030 setObjectName(name); 0031 setAlignWidget(alignWidget); 0032 } 0033 0034 OverlayWidget::~OverlayWidget() 0035 { 0036 } 0037 0038 void OverlayWidget::reposition() 0039 { 0040 if (!mAlignWidget) 0041 { 0042 return; 0043 } 0044 0045 // p is in the alignWidget's coordinates 0046 0047 QPoint p; 0048 0049 // We are always above the alignWidget, right-aligned with it. 0050 0051 p.setX(mAlignWidget->width() - width()); 0052 p.setY(-height()); 0053 0054 // Position in the toplevelwidget's coordinates 0055 0056 QPoint pTopLevel = mAlignWidget->mapTo(topLevelWidget(), p); 0057 0058 // Position in the widget's parentWidget coordinates 0059 0060 QPoint pParent = parentWidget()->mapFrom(topLevelWidget(), pTopLevel); 0061 0062 // Move 'this' to that position. 0063 0064 move(pParent); 0065 } 0066 0067 void OverlayWidget::setAlignWidget(QWidget* const w) 0068 { 0069 if (w == mAlignWidget) 0070 { 0071 return; 0072 } 0073 0074 if (mAlignWidget) 0075 { 0076 mAlignWidget->removeEventFilter(this); 0077 } 0078 0079 mAlignWidget = w; 0080 0081 if (mAlignWidget) 0082 { 0083 mAlignWidget->installEventFilter(this); 0084 } 0085 0086 reposition(); 0087 } 0088 0089 bool OverlayWidget::eventFilter(QObject* o, QEvent* e) 0090 { 0091 if ((o == mAlignWidget) && 0092 ((e->type() == QEvent::Move) || (e->type() == QEvent::Resize))) 0093 { 0094 reposition(); 0095 } 0096 0097 return QFrame::eventFilter(o, e); 0098 } 0099 0100 void OverlayWidget::resizeEvent(QResizeEvent* ev) 0101 { 0102 reposition(); 0103 QFrame::resizeEvent(ev); 0104 } 0105 0106 QWidget* OverlayWidget::alignWidget() const 0107 { 0108 return mAlignWidget; 0109 } 0110 0111 } // namespace Digikam 0112 0113 #include "moc_overlaywidget.cpp"