2019-07-23 22:18:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "widgets/BaseWindow.hpp"
|
2023-03-18 17:30:08 +01:00
|
|
|
#include "widgets/TooltipEntryWidget.hpp"
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2022-12-29 16:07:46 +01:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
2023-03-18 17:30:08 +01:00
|
|
|
#include <QGridLayout>
|
2019-07-23 22:18:36 +02:00
|
|
|
#include <QLabel>
|
2023-03-18 17:30:08 +01:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QVBoxLayout>
|
2019-07-23 22:18:36 +02:00
|
|
|
#include <QWidget>
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
class Image;
|
|
|
|
using ImagePtr = std::shared_ptr<Image>;
|
|
|
|
|
2023-03-18 17:30:08 +01:00
|
|
|
struct TooltipEntry {
|
|
|
|
ImagePtr image;
|
|
|
|
QString text;
|
|
|
|
int customWidth = 0;
|
|
|
|
int customHeight = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class TooltipStyle { Vertical, Grid };
|
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
class TooltipWidget : public BaseWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-10-07 22:42:34 +02:00
|
|
|
static TooltipWidget *instance();
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
TooltipWidget(BaseWidget *parent = nullptr);
|
2022-12-29 16:07:46 +01:00
|
|
|
~TooltipWidget() override = default;
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2023-03-18 17:30:08 +01:00
|
|
|
void setOne(const TooltipEntry &entry,
|
|
|
|
TooltipStyle style = TooltipStyle::Vertical);
|
|
|
|
void set(const std::vector<TooltipEntry> &entries,
|
|
|
|
TooltipStyle style = TooltipStyle::Vertical);
|
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
void setWordWrap(bool wrap);
|
2023-03-18 17:30:08 +01:00
|
|
|
void clearEntries();
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
protected:
|
2022-12-29 16:07:46 +01:00
|
|
|
void showEvent(QShowEvent *) override;
|
|
|
|
void hideEvent(QHideEvent *) override;
|
2019-07-23 22:18:36 +02:00
|
|
|
void changeEvent(QEvent *) override;
|
|
|
|
void leaveEvent(QEvent *) override;
|
|
|
|
void themeChangedEvent() override;
|
|
|
|
void scaleChangedEvent(float) override;
|
2019-08-21 02:37:10 +02:00
|
|
|
void paintEvent(QPaintEvent *) override;
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void updateFont();
|
|
|
|
|
2023-03-18 17:30:08 +01:00
|
|
|
QLayout *currentLayout() const;
|
|
|
|
int currentLayoutCount() const;
|
|
|
|
TooltipEntryWidget *entryAt(int n);
|
|
|
|
|
|
|
|
void setVisibleEntries(int n);
|
|
|
|
void setCurrentStyle(TooltipStyle style);
|
|
|
|
void addNewEntry(int absoluteIndex);
|
|
|
|
|
|
|
|
void deleteCurrentLayout();
|
|
|
|
void initializeVLayout();
|
|
|
|
void initializeGLayout();
|
|
|
|
|
|
|
|
int visibleEntries_ = 0;
|
2022-12-29 16:07:46 +01:00
|
|
|
|
2023-03-18 17:30:08 +01:00
|
|
|
TooltipStyle currentStyle_;
|
|
|
|
QVBoxLayout *vLayout_;
|
|
|
|
QGridLayout *gLayout_;
|
2022-12-29 16:07:46 +01:00
|
|
|
|
|
|
|
pajlada::Signals::SignalHolder connections_;
|
2019-07-23 22:18:36 +02:00
|
|
|
};
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|