diff options
author | Arno <arno@disconnect.de> | 2019-11-22 17:46:39 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2019-11-22 17:46:39 +0100 |
commit | 08b627c59c98d67d057e061612f165b4ff3cb966 (patch) | |
tree | 4d68582e91fe062e7913460a07311a9649c3171d /hoverwindow.cpp | |
parent | b98ca1a0618865c3edd67a29c0af6da1d87ad269 (diff) | |
download | SheMov-08b627c59c98d67d057e061612f165b4ff3cb966.tar.gz SheMov-08b627c59c98d67d057e061612f165b4ff3cb966.tar.bz2 SheMov-08b627c59c98d67d057e061612f165b4ff3cb966.zip |
Get rid of HoverWindow
It depended on X11, because the hover center wasn't where it was
supposed to be, so I worked around it with Xfixes.h, which unfortunately
isn't even available in MSYS2. So another fix for compiling this under
Windows.
Diffstat (limited to 'hoverwindow.cpp')
-rw-r--r-- | hoverwindow.cpp | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/hoverwindow.cpp b/hoverwindow.cpp deleted file mode 100644 index 101265c..0000000 --- a/hoverwindow.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - 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 - 2 of the License, or (at your option) any later version. -*/ - -#include <QHBoxLayout> -#include <QLabel> -#include <QDesktopWidget> -#include <QSize> -#include <QTextDocument> -#include <QSettings> -#include <QPixmap> -#include <QImage> -#include <QPainter> -#include <QFontMetrics> -#include <QBrush> -#include <QPen> -#include <QColor> -#include <QApplication> -#include <QStaticText> -#include <QScreen> - -#include "hoverwindow.h" -#include "smglobals.h" - -HoverWindow::HoverWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mAlignCenter(false), mDesktopHeight(-1){ - setVisible(false); - QSettings s; - int opacity = s.value("ui/hoveropacity", 7).toInt(); - setWindowOpacity(opacity / 10.0); - setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - setStyleSheet("QLabel { background-color: #D6A583; color: black; border-width: 2px; border-style: solid; padding: 4px; }"); - mDesktopHeight = qApp->screens().at(0)->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; - 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()); - int i = 0; - for(i = 0; i < count; ++i){ - curText.append(QString("<li>%1</li>").arg(children.at(i))); - } - if(i < children.count()){ - curText.append("<li>...</li>"); - } - curText.append("</ul>"); - QTextDocument doc; - doc.setHtml(curText); - mLabel->setText(curText); - setMinimumSize(doc.size().width() + 10, doc.size().height() + 10); - setMaximumSize(doc.size().width() + 10, doc.size().height() + 10); - raise(); -} - -void HoverWindow::setPixmap(const QPixmap &pm, bool scale){ - mAlignCenter = true; - QPixmap curPm = pm; - if(scale){ - if(curPm.height() > 500){ - curPm = curPm.scaledToHeight(500); - } - if(curPm.width() > 300){ - curPm = curPm.scaledToWidth(300); - } - } - mLabel->setPixmap(curPm); - setMaximumSize(curPm.width() + 10, curPm.height() + 10); - setMinimumSize(curPm.width() + 10, curPm.height() + 10); - raise(); -} - -void HoverWindow::setData(const QList<QVariant> &data){ - if(data.isEmpty()){ - return; - } - if(data.at(0).canConvert(QVariant::Pixmap)){ - setPixmap(data.at(0).value<QPixmap>()); - return; - } - if(data.size() != 2){ - return; - } - QStringList dataList = data.at(1).toStringList(); - if(dataList.isEmpty()){ - dataList << tr("<empty>"); - } - setContent(data.at(0).toString(), dataList); -} - -void HoverWindow::setCaption(const QString &caption){ - const QPixmap *pm = mLabel->pixmap(); - if(!pm){ - return; - } - QFontMetrics fm = qApp->fontMetrics(); - QString elidedCap = fm.elidedText(caption, Qt::ElideLeft, pm->size().width() - 18, Qt::TextSingleLine); - QStaticText myCap(elidedCap); - QImage img = pm->toImage(); - QPainter *p = new QPainter(&img); - QColor bgColor(Qt::white); - p->setBrush(QBrush(bgColor)); - p->setPen(Qt::NoPen); - p->setOpacity(0.4); - qreal xStart = (mLabel->width() - myCap.size().width() - 9) / 2.0; - p->drawRect(QRect(QPoint(xStart, 5), QSize(myCap.size().toSize()))); - p->setOpacity(1.0); - p->setPen(Qt::black); - p->drawStaticText(xStart, 5, myCap); - delete p; - mLabel->setPixmap(QPixmap::fromImage(img)); -} - -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); - } - if(hoverPos.y() < 0){ - hoverPos = QPoint(hoverPos.x(), 0); - } - if(hoverPos.y() + height() > mDesktopHeight){ - hoverPos = QPoint(hoverPos.x(), mDesktopHeight - height()); - } - move(hoverPos); -} |