diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/gui/overlaywidget.cpp | |
download | tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip |
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/overlaywidget.cpp')
-rw-r--r-- | src/gui/overlaywidget.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/gui/overlaywidget.cpp b/src/gui/overlaywidget.cpp new file mode 100644 index 0000000..6214ca8 --- /dev/null +++ b/src/gui/overlaywidget.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + copyright : (C) 2005-2006 by Robby Stephenson + email : robby@periapsis.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#include "overlaywidget.h" + +#include <qlayout.h> + +using Tellico::GUI::OverlayWidget; + +OverlayWidget::OverlayWidget(QWidget* parent, QWidget* anchor) : QFrame(parent) + , m_anchor(anchor) + , m_corner(TopRight) { + m_anchor->installEventFilter(this); + reposition(); + hide(); +} + +void OverlayWidget::setCorner(Corner corner_) { + if(corner_ == m_corner) { + return; + } + m_corner = corner_; + reposition(); +} + +void OverlayWidget::addWidget(QWidget* widget_) { + layout()->add(widget_); + adjustSize(); +} + +void OverlayWidget::reposition() { + if(!m_anchor) { + return; + } + + setMaximumSize(parentWidget()->size()); + adjustSize(); + + QPoint p; + + switch(m_corner) { + case BottomLeft: + p.setX(0); + p.setY(m_anchor->height()); + break; + + case BottomRight: + p.setX(m_anchor->width() - width()); + p.setY(m_anchor->height()); + break; + + case TopLeft: + p.setX(0); + p.setY(-1 * height()); + break; + + case TopRight: + p.setX(m_anchor->width() - width()); + p.setY(-1 * height()); + } + + // Position in the toplevelwidget's coordinates + QPoint pTopLevel = m_anchor->mapTo(topLevelWidget(), p); + // Position in the widget's parentWidget coordinates + QPoint pParent = parentWidget()->mapFrom(topLevelWidget(), pTopLevel); + // keep it on the screen + if(pParent.x() < 0) { + pParent.rx() = 0; + } + move(pParent); +} + +bool OverlayWidget::eventFilter(QObject* object_, QEvent* event_) { + if(object_ == m_anchor && (event_->type() == QEvent::Move || event_->type() == QEvent::Resize)) { + reposition(); + } + + return QFrame::eventFilter(object_, event_); +} + +void OverlayWidget::resizeEvent(QResizeEvent* event_) { + reposition(); + QFrame::resizeEvent(event_); +} + +bool OverlayWidget::event(QEvent* event_) { + if(event_->type() == QEvent::ChildInserted) { + adjustSize(); + } + + return QFrame::event(event_); +} + +#include "overlaywidget.moc" |