summaryrefslogtreecommitdiffstats
path: root/hoverwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hoverwindow.cpp')
-rw-r--r--hoverwindow.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/hoverwindow.cpp b/hoverwindow.cpp
index 7f2e4af..6ca6bce 100644
--- a/hoverwindow.cpp
+++ b/hoverwindow.cpp
@@ -9,21 +9,30 @@
#include <QLabel>
#include <QApplication>
#include <QDesktopWidget>
+#include <QSize>
#include "hoverwindow.h"
+#include "smglobals.h"
-HoverWindow::HoverWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){
+HoverWindow::HoverWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mAlignCenter(false), mDesktopHeight(-1){
setVisible(false);
setWindowOpacity(0.7);
+ setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
setStyleSheet("QLabel { background-color: #D6A583; color: black; border-width: 2px; border-style: solid; padding: 4px; }");
- QHBoxLayout *mainLayout = new QHBoxLayout;
- mainLayout->setContentsMargins(4, 4, 4, 4);
+ QDesktopWidget *desktop = qApp->desktop();
+ mDesktopHeight = desktop->availableGeometry().height();
+ QSize curSize = SmGlobals::instance()->cursorSize();
+ setHoverOffset(QPoint(curSize.width() + 30, 0));
+ mMainLayout = new QHBoxLayout;
+ mMainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
+ mMainLayout->setContentsMargins(4, 4, 4, 4);
mLabel = new QLabel;
- mainLayout->addWidget(mLabel);
- setLayout(mainLayout);
+ mMainLayout->addWidget(mLabel);
+ setLayout(mMainLayout);
}
void HoverWindow::setContent(const QString &parent, const QStringList &children){
+ mAlignCenter = false;
QString curText = QString("<p style=\"align: center; text-decoration: underline; font-weight: bold; margin-bottom: 0;\">%1</p>").arg(parent);
curText.append("<ul style=\"margin-left: -25; margin-top: 0px;\">");
int count = qMin(6, children.size());
@@ -39,6 +48,7 @@ void HoverWindow::setContent(const QString &parent, const QStringList &children)
}
void HoverWindow::setPixmap(const QPixmap &pm){
+ mAlignCenter = true;
QPixmap curPm = pm;
if(curPm.height() > 500){
curPm = curPm.scaledToHeight(500);
@@ -47,6 +57,8 @@ void HoverWindow::setPixmap(const QPixmap &pm){
curPm = curPm.scaledToWidth(300);
}
mLabel->setPixmap(curPm);
+ setMaximumSize(curPm.width() + 10, curPm.height() + 10);
+ setMinimumSize(curPm.width() + 10, curPm.height() + 10);
}
void HoverWindow::setData(const QList<QVariant> &data){
@@ -72,16 +84,17 @@ int HoverWindow::pixmapHeight() const{
return pm ? pm->height() : 0;
}
-void HoverWindow::setPos(const QPoint &cursorPos){
- if(cursorPos.y() - height() / 2 < 0){
- move(QPoint(cursorPos.x(), 0));
- return;
+void HoverWindow::setPos(){
+ const QPoint globalPos(QCursor::pos());
+ QPoint hoverPos(globalPos.x() + mHoverOffset.x(), globalPos.y() + mHoverOffset.y());
+ if(mAlignCenter){
+ hoverPos = QPoint(hoverPos.x(), hoverPos.y() - height() / 2);
}
- QDesktopWidget *desktop = qApp->desktop();
- int desktopHeight = desktop->availableGeometry().height();
- if(cursorPos.y() + height() / 2 > desktopHeight){
- move(QPoint(cursorPos.x(), desktopHeight - height()));
- return;
+ if(hoverPos.y() < 0){
+ hoverPos = QPoint(hoverPos.x(), 0);
+ }
+ if(hoverPos.y() + height() > mDesktopHeight){
+ hoverPos = QPoint(hoverPos.x(), mDesktopHeight - height());
}
- move(cursorPos);
+ move(hoverPos);
}