strawberry-audio-player-win.../src/widgets/freespacebar.h

80 lines
2.1 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef FREESPACEBAR_H
#define FREESPACEBAR_H
#include <QtGlobal>
#include <QObject>
2018-02-27 18:06:05 +01:00
#include <QWidget>
#include <QString>
#include <QColor>
2020-02-09 02:29:35 +01:00
#include <QRgb>
#include <QRect>
#include <QSize>
2020-02-09 02:29:35 +01:00
class QPainter;
class QPaintEvent;
2018-02-27 18:06:05 +01:00
class FreeSpaceBar : public QWidget {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit FreeSpaceBar(QWidget *parent = nullptr);
2018-02-27 18:06:05 +01:00
2021-10-30 02:21:29 +02:00
void set_free_bytes(const quint64 bytes) { free_ = bytes; update(); }
void set_additional_bytes(const quint64 bytes) { additional_ = bytes; update(); }
void set_total_bytes(const quint64 bytes) { total_ = bytes; update(); }
2018-02-27 18:06:05 +01:00
2021-06-12 20:53:23 +02:00
void set_free_text(const QString &text) { free_text_ = text; update(); }
void set_additional_text(const QString &text) { additional_text_ = text; update(); }
void set_used_text(const QString &text) { used_text_ = text; update(); }
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
QSize sizeHint() const override;
2018-02-27 18:06:05 +01:00
2020-04-07 16:49:15 +02:00
protected:
2020-06-15 21:55:05 +02:00
void paintEvent(QPaintEvent*) override;
2018-02-27 18:06:05 +01:00
2020-04-07 16:49:15 +02:00
private:
2018-02-27 18:06:05 +01:00
struct Label {
2020-04-07 16:49:15 +02:00
explicit Label(const QString &t, const QColor &c) : text(t), color(c) {}
2018-02-27 18:06:05 +01:00
QString text;
QColor color;
};
2021-10-30 02:21:29 +02:00
static QString TextForSize(const QString &prefix, const quint64 size);
2018-02-27 18:06:05 +01:00
2021-06-20 19:04:08 +02:00
void DrawBar(QPainter *p, const QRect r);
void DrawText(QPainter *p, const QRect r);
2018-02-27 18:06:05 +01:00
2020-04-07 16:49:15 +02:00
private:
2021-10-30 02:21:29 +02:00
quint64 free_;
quint64 additional_;
quint64 total_;
2018-02-27 18:06:05 +01:00
QString free_text_;
QString additional_text_;
2024-06-08 02:37:28 +02:00
QString exceeded_text_;
2018-02-27 18:06:05 +01:00
QString used_text_;
};
#endif // FREESPACEBAR_H