/* 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 #include #include #include #include "hoverwindow.h" HoverWindow::HoverWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ setVisible(false); setWindowOpacity(0.7); 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); mLabel = new QLabel; mainLayout->addWidget(mLabel); setLayout(mainLayout); } void HoverWindow::setContent(const QString &parent, const QStringList &children){ QString curText = QString("

%1

").arg(parent); curText.append("
    "); int count = qMin(6, children.size()); int i = 0; for(i = 0; i < count; ++i){ curText.append(QString("
  • %1
  • ").arg(children.at(i))); } if(i < children.count()){ curText.append("
  • ...
  • "); } curText.append("
"); mLabel->setText(curText); } void HoverWindow::setPixmap(const QPixmap &pm){ QPixmap curPm = pm; if(curPm.height() > 500){ curPm = curPm.scaledToHeight(500); } if(curPm.width() > 300){ curPm = curPm.scaledToWidth(300); } mLabel->setPixmap(curPm); } int HoverWindow::pixmapHeight() const{ const QPixmap *pm = mLabel->pixmap(); return pm ? pm->height() : 0; } void HoverWindow::setPos(const QPoint &cursorPos){ if(cursorPos.y() - height() / 2 < 0){ move(QPoint(cursorPos.x(), 0)); return; } QDesktopWidget *desktop = qApp->desktop(); int desktopHeight = desktop->availableGeometry().height(); if(cursorPos.y() + height() / 2 > desktopHeight){ move(QPoint(cursorPos.x(), desktopHeight - height())); return; } move(cursorPos); }