Optimize includes a bit

This commit is contained in:
Nicolas Werner 2020-01-31 06:12:02 +01:00
parent 558fd10f7b
commit 4cd260bfcf
41 changed files with 271 additions and 228 deletions

View file

@ -256,6 +256,7 @@ set(SRC_FILES
# UI components # UI components
src/ui/Avatar.cpp src/ui/Avatar.cpp
src/ui/Badge.cpp src/ui/Badge.cpp
src/ui/DropShadow.cpp
src/ui/LoadingIndicator.cpp src/ui/LoadingIndicator.cpp
src/ui/InfoMessage.cpp src/ui/InfoMessage.cpp
src/ui/FlatButton.cpp src/ui/FlatButton.cpp

View file

@ -84,7 +84,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
// SideBar // SideBar
sideBar_ = new QFrame(this); sideBar_ = new QFrame(this);
sideBar_->setObjectName("sideBar"); sideBar_->setObjectName("sideBar");
sideBar_->setMinimumWidth(utils::calculateSidebarSizes(QFont{}).normal); sideBar_->setMinimumWidth(::splitter::calculateSidebarSizes(QFont{}).normal);
sideBarLayout_ = new QVBoxLayout(sideBar_); sideBarLayout_ = new QVBoxLayout(sideBar_);
sideBarLayout_->setSpacing(0); sideBarLayout_->setSpacing(0);
sideBarLayout_->setMargin(0); sideBarLayout_->setMargin(0);
@ -1307,7 +1307,7 @@ ChatPage::timelineWidth()
bool bool
ChatPage::isSideBarExpanded() ChatPage::isSideBarExpanded()
{ {
const auto sz = utils::calculateSidebarSizes(QFont{}); const auto sz = splitter::calculateSidebarSizes(QFont{});
return sideBar_->size().width() > sz.normal; return sideBar_->size().width() > sz.normal;
} }

View file

@ -2,7 +2,9 @@
#include "Cache.h" #include "Cache.h"
#include "Logging.h" #include "Logging.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "Utils.h" #include "Splitter.h"
#include <mtx/responses/groups.hpp>
#include <QLabel> #include <QLabel>
@ -20,7 +22,7 @@ CommunitiesList::CommunitiesList(QWidget *parent)
topLayout_->setSpacing(0); topLayout_->setSpacing(0);
topLayout_->setMargin(0); topLayout_->setMargin(0);
const auto sideBarSizes = utils::calculateSidebarSizes(QFont{}); const auto sideBarSizes = splitter::calculateSidebarSizes(QFont{});
setFixedWidth(sideBarSizes.groups); setFixedWidth(sideBarSizes.groups);
scrollArea_ = new QScrollArea(this); scrollArea_ = new QScrollArea(this);
@ -185,7 +187,8 @@ void
CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img) CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img)
{ {
if (!communityExists(community_id)) { if (!communityExists(community_id)) {
qWarning() << "Avatar update on nonexistent community" << community_id; nhlog::ui()->warn("Avatar update on nonexistent community {}",
community_id.toStdString());
return; return;
} }
@ -196,7 +199,7 @@ void
CommunitiesList::highlightSelectedCommunity(const QString &community_id) CommunitiesList::highlightSelectedCommunity(const QString &community_id)
{ {
if (!communityExists(community_id)) { if (!communityExists(community_id)) {
qDebug() << "CommunitiesList: clicked unknown community"; nhlog::ui()->debug("CommunitiesList: clicked unknown community");
return; return;
} }

View file

@ -8,6 +8,11 @@
#include "CommunitiesListItem.h" #include "CommunitiesListItem.h"
#include "ui/Theme.h" #include "ui/Theme.h"
namespace mtx::responses {
struct GroupProfile;
struct JoinedGroups;
}
class CommunitiesList : public QWidget class CommunitiesList : public QWidget
{ {
Q_OBJECT Q_OBJECT

View file

@ -1,4 +1,7 @@
#include "CommunitiesListItem.h" #include "CommunitiesListItem.h"
#include <QMouseEvent>
#include "Utils.h" #include "Utils.h"
#include "ui/Painter.h" #include "ui/Painter.h"
#include "ui/Ripple.h" #include "ui/Ripple.h"

View file

@ -1,17 +1,14 @@
#pragma once #pragma once
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include <QSharedPointer> #include <QSharedPointer>
#include <QWidget> #include <QWidget>
#include <mtx/responses/groups.hpp>
#include "Config.h" #include "Config.h"
#include "ui/Theme.h" #include "ui/Theme.h"
class RippleOverlay; class RippleOverlay;
class QPainter;
class QMouseEvent;
class CommunitiesListItem : public QWidget class CommunitiesListItem : public QWidget
{ {

View file

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include <mtx/identifiers.hpp> #include <mtx/identifiers.hpp>

View file

@ -31,6 +31,7 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "RegisterPage.h" #include "RegisterPage.h"
#include "Splitter.h"
#include "TrayIcon.h" #include "TrayIcon.h"
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "Utils.h" #include "Utils.h"
@ -191,7 +192,7 @@ MainWindow::resizeEvent(QResizeEvent *event)
void void
MainWindow::adjustSideBars() MainWindow::adjustSideBars()
{ {
const auto sz = utils::calculateSidebarSizes(QFont{}); const auto sz = splitter::calculateSidebarSizes(QFont{});
const uint64_t timelineWidth = chat_page_->timelineWidth(); const uint64_t timelineWidth = chat_page_->timelineWidth();
const uint64_t minAvailableWidth = sz.collapsePoint + sz.groups; const uint64_t minAvailableWidth = sz.collapsePoint + sz.groups;

View file

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include <QTimer> #include <QTimer>

View file

@ -16,7 +16,6 @@
*/ */
#include <QDateTime> #include <QDateTime>
#include <QDebug>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter> #include <QPainter>
#include <QSettings> #include <QSettings>
@ -26,6 +25,7 @@
#include "Cache.h" #include "Cache.h"
#include "Config.h" #include "Config.h"
#include "RoomInfoListItem.h" #include "RoomInfoListItem.h"
#include "Splitter.h"
#include "Utils.h" #include "Utils.h"
#include "ui/Menu.h" #include "ui/Menu.h"
#include "ui/Ripple.h" #include "ui/Ripple.h"
@ -116,7 +116,7 @@ RoomInfoListItem::resizeEvent(QResizeEvent *)
QPainterPath path; QPainterPath path;
path.addRect(0, 0, width(), height()); path.addRect(0, 0, width(), height());
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{}); const auto sidebarSizes = splitter::calculateSidebarSizes(QFont{});
if (width() > sidebarSizes.small) if (width() > sidebarSizes.small)
setToolTip(""); setToolTip("");
@ -165,7 +165,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
// Description line with the default font. // Description line with the default font.
int bottom_y = wm.maxHeight - wm.padding - metrics.ascent() / 2; int bottom_y = wm.maxHeight - wm.padding - metrics.ascent() / 2;
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{}); const auto sidebarSizes = splitter::calculateSidebarSizes(QFont{});
if (width() > sidebarSizes.small) { if (width() > sidebarSizes.small) {
QFont headingFont; QFont headingFont;

View file

@ -17,18 +17,14 @@
#include <limits> #include <limits>
#include <QApplication>
#include <QBuffer>
#include <QObject> #include <QObject>
#include <QPainter>
#include <QTimer> #include <QTimer>
#include "Cache.h"
#include "Logging.h" #include "Logging.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "MatrixClient.h"
#include "RoomInfoListItem.h" #include "RoomInfoListItem.h"
#include "RoomList.h" #include "RoomList.h"
#include "UserSettingsPage.h"
#include "Utils.h" #include "Utils.h"
#include "ui/OverlayModal.h" #include "ui/OverlayModal.h"

View file

@ -1,15 +1,15 @@
#include <QDebug>
#include <QIcon> #include <QIcon>
#include <QPainter>
#include <QResizeEvent>
#include <mtx/requests.hpp> #include <mtx/requests.hpp>
#include "Config.h" #include "Config.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "SideBarActions.h" #include "SideBarActions.h"
#include "Utils.h" #include "Splitter.h"
#include "ui/FlatButton.h" #include "ui/FlatButton.h"
#include "ui/Menu.h" #include "ui/Menu.h"
#include "ui/OverlayModal.h"
SideBarActions::SideBarActions(QWidget *parent) SideBarActions::SideBarActions(QWidget *parent)
: QWidget{parent} : QWidget{parent}
@ -93,7 +93,7 @@ SideBarActions::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{}); const auto sidebarSizes = splitter::calculateSidebarSizes(QFont{});
if (width() <= sidebarSizes.small) { if (width() <= sidebarSizes.small) {
roomDirectory_->hide(); roomDirectory_->hide();

View file

@ -2,7 +2,6 @@
#include <QAction> #include <QAction>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QResizeEvent>
#include <QWidget> #include <QWidget>
namespace mtx { namespace mtx {
@ -13,6 +12,7 @@ struct CreateRoom;
class Menu; class Menu;
class FlatButton; class FlatButton;
class QResizeEvent;
class SideBarActions : public QWidget class SideBarActions : public QWidget
{ {

View file

@ -16,19 +16,20 @@
*/ */
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QSettings> #include <QSettings>
#include <QShortcut> #include <QShortcut>
#include "Config.h" #include "Config.h"
#include "Logging.h"
#include "Splitter.h" #include "Splitter.h"
#include "Utils.h"
constexpr auto MaxWidth = (1 << 24) - 1; constexpr auto MaxWidth = (1 << 24) - 1;
Splitter::Splitter(QWidget *parent) Splitter::Splitter(QWidget *parent)
: QSplitter(parent) : QSplitter(parent)
, sz_{utils::calculateSidebarSizes(QFont{})} , sz_{splitter::calculateSidebarSizes(QFont{})}
{ {
connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved); connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved);
setChildrenCollapsible(false); setChildrenCollapsible(false);
@ -80,7 +81,7 @@ Splitter::onSplitterMoved(int pos, int index)
auto s = sizes(); auto s = sizes();
if (s.count() < 2) { if (s.count() < 2) {
qWarning() << "Splitter needs at least two children"; nhlog::ui()->warn("Splitter needs at least two children");
return; return;
} }
@ -165,3 +166,18 @@ Splitter::showFullRoomList()
left->show(); left->show();
left->setMaximumWidth(MaxWidth); left->setMaximumWidth(MaxWidth);
} }
splitter::SideBarSizes
splitter::calculateSidebarSizes(const QFont &f)
{
const auto height = static_cast<double>(QFontMetrics{f}.lineSpacing());
SideBarSizes sz;
sz.small = std::ceil(3.5 * height + height / 4.0);
sz.normal = std::ceil(16 * height);
sz.groups = std::ceil(3 * height);
sz.collapsePoint = 2 * sz.normal;
return sz;
}

View file

@ -17,9 +17,21 @@
#pragma once #pragma once
#include "Utils.h"
#include <QSplitter> #include <QSplitter>
namespace splitter {
struct SideBarSizes
{
int small;
int normal;
int groups;
int collapsePoint;
};
SideBarSizes
calculateSidebarSizes(const QFont &f);
}
class Splitter : public QSplitter class Splitter : public QSplitter
{ {
Q_OBJECT Q_OBJECT
@ -45,5 +57,5 @@ private:
int leftMoveCount_ = 0; int leftMoveCount_ = 0;
int rightMoveCount_ = 0; int rightMoveCount_ = 0;
utils::SideBarSizes sz_; splitter::SideBarSizes sz_;
}; };

View file

@ -16,12 +16,9 @@
*/ */
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QBuffer> #include <QBuffer>
#include <QClipboard> #include <QClipboard>
#include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QImageReader>
#include <QMimeData> #include <QMimeData>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QMimeType> #include <QMimeType>
@ -31,7 +28,7 @@
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Config.h" #include "Logging.h"
#include "TextInputWidget.h" #include "TextInputWidget.h"
#include "Utils.h" #include "Utils.h"
#include "ui/FlatButton.h" #include "ui/FlatButton.h"

View file

@ -23,7 +23,6 @@
#include <optional> #include <optional>
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPaintEvent> #include <QPaintEvent>
#include <QTextEdit> #include <QTextEdit>

View file

@ -15,8 +15,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QDebug> #include <QAction>
#include <QIcon>
#include <QLabel>
#include <QPaintEvent>
#include <QPainter>
#include <QPen>
#include <QPoint>
#include <QStyle>
#include <QStyleOption> #include <QStyleOption>
#include <QVBoxLayout>
#include "Config.h" #include "Config.h"
#include "MainWindow.h" #include "MainWindow.h"
@ -210,3 +218,19 @@ TopRoomBar::updateRoomTopic(QString topic)
topicLabel_->setHtml(topic); topicLabel_->setHtml(topic);
update(); update();
} }
void
TopRoomBar::mousePressEvent(QMouseEvent *)
{
if (roomSettings_ != nullptr)
roomSettings_->trigger();
}
void
TopRoomBar::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -17,17 +17,9 @@
#pragma once #pragma once
#include <QAction> #include <QColor>
#include <QIcon> #include <QStringList>
#include <QImage> #include <QWidget>
#include <QLabel>
#include <QPaintEvent>
#include <QPainter>
#include <QPen>
#include <QPoint>
#include <QStyle>
#include <QStyleOption>
#include <QVBoxLayout>
class Avatar; class Avatar;
class FlatButton; class FlatButton;
@ -35,6 +27,12 @@ class Menu;
class TextLabel; class TextLabel;
class OverlayModal; class OverlayModal;
class QPainter;
class QLabel;
class QIcon;
class QHBoxLayout;
class QVBoxLayout;
class TopRoomBar : public QWidget class TopRoomBar : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -67,19 +65,8 @@ signals:
void mentionsClicked(const QPoint &pos); void mentionsClicked(const QPoint &pos);
protected: protected:
void mousePressEvent(QMouseEvent *) override void mousePressEvent(QMouseEvent *) override;
{ void paintEvent(QPaintEvent *) override;
if (roomSettings_ != nullptr)
roomSettings_->trigger();
}
void paintEvent(QPaintEvent *) override
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
private: private:
QHBoxLayout *topLayout_ = nullptr; QHBoxLayout *topLayout_ = nullptr;

View file

@ -15,9 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QAction>
#include <QApplication> #include <QApplication>
#include <QList> #include <QList>
#include <QMenu> #include <QMenu>
#include <QPainter>
#include <QTimer> #include <QTimer>
#include "TrayIcon.h" #include "TrayIcon.h"

View file

@ -17,13 +17,14 @@
#pragma once #pragma once
#include <QAction>
#include <QIcon> #include <QIcon>
#include <QIconEngine> #include <QIconEngine>
#include <QPainter>
#include <QRect> #include <QRect>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
class QAction;
class QPainter;
class MsgCountComposedIcon : public QIconEngine class MsgCountComposedIcon : public QIconEngine
{ {
public: public:

View file

@ -16,14 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QPainter>
#include <QTimer> #include <QTimer>
#include <iostream> #include <iostream>
#include "Config.h" #include "Config.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "Splitter.h"
#include "UserInfoWidget.h" #include "UserInfoWidget.h"
#include "Utils.h"
#include "ui/Avatar.h" #include "ui/Avatar.h"
#include "ui/FlatButton.h" #include "ui/FlatButton.h"
#include "ui/OverlayModal.h" #include "ui/OverlayModal.h"
@ -108,7 +109,7 @@ UserInfoWidget::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
const auto sz = utils::calculateSidebarSizes(QFont{}); const auto sz = splitter::calculateSidebarSizes(QFont{});
if (width() <= sz.small) { if (width() <= sz.small) {
topLayout_->setContentsMargins(0, 0, logoutButtonSize_, 0); topLayout_->setContentsMargins(0, 0, logoutButtonSize_, 0);

View file

@ -22,6 +22,7 @@
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QPainter>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QPushButton> #include <QPushButton>
#include <QScrollArea> #include <QScrollArea>

View file

@ -22,6 +22,25 @@ using TimelineEvent = mtx::events::collections::TimelineEvents;
QHash<QString, QString> authorColors_; QHash<QString, QString> authorColors_;
template<class T, class Event>
static DescInfo
createDescriptionInfo(const Event &event, const QString &localUser, const QString &room_id)
{
const auto msg = std::get<T>(event);
const auto sender = QString::fromStdString(msg.sender);
const auto username = cache::displayName(room_id, sender);
const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts);
return DescInfo{
QString::fromStdString(msg.event_id),
sender,
utils::messageDescription<T>(
username, QString::fromStdString(msg.content.body).trimmed(), sender == localUser),
utils::descriptiveTime(ts),
ts};
}
QString QString
utils::localUser() utils::localUser()
{ {
@ -633,16 +652,3 @@ utils::restoreCombobox(QComboBox *combo, const QString &value)
} }
} }
utils::SideBarSizes
utils::calculateSidebarSizes(const QFont &f)
{
const auto height = static_cast<double>(QFontMetrics{f}.lineSpacing());
SideBarSizes sz;
sz.small = std::ceil(3.5 * height + height / 4.0);
sz.normal = std::ceil(16 * height);
sz.groups = std::ceil(3 * height);
sz.collapsePoint = 2 * sz.normal;
return sz;
}

View file

@ -2,8 +2,6 @@
#include <variant> #include <variant>
#include "RoomInfoListItem.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDateTime> #include <QDateTime>
#include <QPixmap> #include <QPixmap>
@ -12,6 +10,8 @@
#include <qmath.h> #include <qmath.h>
struct DescInfo;
namespace cache { namespace cache {
// Forward declarations to prevent dependency on Cache.h, since this header is included often! // Forward declarations to prevent dependency on Cache.h, since this header is included often!
QString QString
@ -166,25 +166,6 @@ messageDescription(const QString &username = "",
} }
} }
template<class T, class Event>
DescInfo
createDescriptionInfo(const Event &event, const QString &localUser, const QString &room_id)
{
const auto msg = std::get<T>(event);
const auto sender = QString::fromStdString(msg.sender);
const auto username = cache::displayName(room_id, sender);
const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts);
return DescInfo{QString::fromStdString(msg.event_id),
sender,
messageDescription<T>(username,
QString::fromStdString(msg.content.body).trimmed(),
sender == localUser),
utils::descriptiveTime(ts),
ts};
}
//! Scale down an image to fit to the given width & height limitations. //! Scale down an image to fit to the given width & height limitations.
QPixmap QPixmap
scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source); scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source);
@ -326,14 +307,4 @@ centerWidget(QWidget *widget, QWidget *parent);
void void
restoreCombobox(QComboBox *combo, const QString &value); restoreCombobox(QComboBox *combo, const QString &value);
struct SideBarSizes
{
int small;
int normal;
int groups;
int collapsePoint;
};
SideBarSizes
calculateSidebarSizes(const QFont &f);
} }

View file

@ -17,6 +17,7 @@
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
#include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include "Config.h" #include "Config.h"

View file

@ -13,6 +13,7 @@
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Config.h" #include "Config.h"
#include "Logging.h"
#include "Utils.h" #include "Utils.h"
#include "ui/Avatar.h" #include "ui/Avatar.h"
@ -116,7 +117,7 @@ MemberList::MemberList(const QString &room_id, QWidget *parent)
try { try {
addUsers(cache::getMembers(room_id_.toStdString())); addUsers(cache::getMembers(room_id_.toStdString()));
} catch (const lmdb::error &e) { } catch (const lmdb::error &e) {
qCritical() << e.what(); nhlog::db()->critical("Failed to retrieve members from cache: {}", e.what());
} }
auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this); auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this);

View file

@ -1,13 +1,12 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QListWidget> #include <QListWidget>
#include <QSettings>
#include <QShortcut> #include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "AvatarProvider.h"
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Logging.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "Utils.h" #include "Utils.h"
#include "dialogs/UserProfile.h" #include "dialogs/UserProfile.h"

View file

@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QDebug>
#include <QPainter> #include <QPainter>
#include <QSettings> #include <QSettings>

View file

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QPainter>
#include <QPushButton> #include <QPushButton>
#include <QScrollBar> #include <QScrollBar>
#include <QVBoxLayout> #include <QVBoxLayout>

View file

@ -2,19 +2,14 @@
#include <mtx/responses.hpp> #include <mtx/responses.hpp>
#include <QApplication>
#include <QEvent>
#include <QMap> #include <QMap>
#include <QPaintEvent> #include <QPaintEvent>
#include <QScrollArea> #include <QScrollArea>
#include <QScrollBar>
#include <QString> #include <QString>
#include <QTabWidget> #include <QTabWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
#include <Qt>
#include "Logging.h"
namespace popups { namespace popups {

View file

@ -6,16 +6,18 @@
#include <QHash> #include <QHash>
#include <QSet> #include <QSet>
#include <mtx/common.hpp>
#include <mtx/responses.hpp>
#include <mtxclient/http/errors.hpp> #include <mtxclient/http/errors.hpp>
#include "CacheCryptoStructs.h" #include "CacheCryptoStructs.h"
#include "Logging.h"
namespace mtx::http { namespace mtx::http {
using RequestErr = const std::optional<mtx::http::ClientError> &; using RequestErr = const std::optional<mtx::http::ClientError> &;
} }
namespace mtx::responses {
struct Timeline;
struct Messages;
struct ClaimKeys;
}
namespace qml_mtx_events { namespace qml_mtx_events {
Q_NAMESPACE Q_NAMESPACE

110
src/ui/DropShadow.cpp Normal file
View file

@ -0,0 +1,110 @@
#include "DropShadow.h"
#include <QLinearGradient>
#include <QPainter>
void DropShadow::draw(QPainter &painter,
qint16 margin,
qreal radius,
QColor start,
QColor end,
qreal startPosition,
qreal endPosition0,
qreal endPosition1,
qreal width,
qreal height)
{
painter.setPen(Qt::NoPen);
QLinearGradient gradient;
gradient.setColorAt(startPosition, start);
gradient.setColorAt(endPosition0, end);
// Right
QPointF right0(width - margin, height / 2);
QPointF right1(width, height / 2);
gradient.setStart(right0);
gradient.setFinalStop(right1);
painter.setBrush(QBrush(gradient));
// Deprecated in 5.13: painter.drawRoundRect(
// QRectF(QPointF(width - margin * radius, margin), QPointF(width, height -
// margin)), 0.0, 0.0);
painter.drawRoundedRect(
QRectF(QPointF(width - margin * radius, margin), QPointF(width, height - margin)),
0.0,
0.0);
// Left
QPointF left0(margin, height / 2);
QPointF left1(0, height / 2);
gradient.setStart(left0);
gradient.setFinalStop(left1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(margin * radius, margin), QPointF(0, height - margin)), 0.0, 0.0);
// Top
QPointF top0(width / 2, margin);
QPointF top1(width / 2, 0);
gradient.setStart(top0);
gradient.setFinalStop(top1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(width - margin, 0), QPointF(margin, margin)), 0.0, 0.0);
// Bottom
QPointF bottom0(width / 2, height - margin);
QPointF bottom1(width / 2, height);
gradient.setStart(bottom0);
gradient.setFinalStop(bottom1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(margin, height - margin), QPointF(width - margin, height)),
0.0,
0.0);
// BottomRight
QPointF bottomright0(width - margin, height - margin);
QPointF bottomright1(width, height);
gradient.setStart(bottomright0);
gradient.setFinalStop(bottomright1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(bottomright0, bottomright1), 0.0, 0.0);
// BottomLeft
QPointF bottomleft0(margin, height - margin);
QPointF bottomleft1(0, height);
gradient.setStart(bottomleft0);
gradient.setFinalStop(bottomleft1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(bottomleft0, bottomleft1), 0.0, 0.0);
// TopLeft
QPointF topleft0(margin, margin);
QPointF topleft1(0, 0);
gradient.setStart(topleft0);
gradient.setFinalStop(topleft1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(topleft0, topleft1), 0.0, 0.0);
// TopRight
QPointF topright0(width - margin, margin);
QPointF topright1(width, 0);
gradient.setStart(topright0);
gradient.setFinalStop(topright1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(topright0, topright1), 0.0, 0.0);
// Widget
painter.setBrush(QBrush("#FFFFFF"));
painter.setRenderHint(QPainter::Antialiasing);
painter.drawRoundedRect(
QRectF(QPointF(margin, margin), QPointF(width - margin, height - margin)),
radius,
radius);
}

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <QColor> #include <QColor>
#include <QLinearGradient>
#include <QPainter> class QPainter;
class DropShadow class DropShadow
{ {
@ -16,99 +16,5 @@ public:
qreal endPosition0, qreal endPosition0,
qreal endPosition1, qreal endPosition1,
qreal width, qreal width,
qreal height) qreal height);
{
painter.setPen(Qt::NoPen);
QLinearGradient gradient;
gradient.setColorAt(startPosition, start);
gradient.setColorAt(endPosition0, end);
// Right
QPointF right0(width - margin, height / 2);
QPointF right1(width, height / 2);
gradient.setStart(right0);
gradient.setFinalStop(right1);
painter.setBrush(QBrush(gradient));
// Deprecated in 5.13: painter.drawRoundRect(
// QRectF(QPointF(width - margin * radius, margin), QPointF(width, height -
// margin)), 0.0, 0.0);
painter.drawRoundedRect(
QRectF(QPointF(width - margin * radius, margin), QPointF(width, height - margin)),
0.0,
0.0);
// Left
QPointF left0(margin, height / 2);
QPointF left1(0, height / 2);
gradient.setStart(left0);
gradient.setFinalStop(left1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(margin * radius, margin), QPointF(0, height - margin)), 0.0, 0.0);
// Top
QPointF top0(width / 2, margin);
QPointF top1(width / 2, 0);
gradient.setStart(top0);
gradient.setFinalStop(top1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(width - margin, 0), QPointF(margin, margin)), 0.0, 0.0);
// Bottom
QPointF bottom0(width / 2, height - margin);
QPointF bottom1(width / 2, height);
gradient.setStart(bottom0);
gradient.setFinalStop(bottom1);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(
QRectF(QPointF(margin, height - margin), QPointF(width - margin, height)),
0.0,
0.0);
// BottomRight
QPointF bottomright0(width - margin, height - margin);
QPointF bottomright1(width, height);
gradient.setStart(bottomright0);
gradient.setFinalStop(bottomright1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(bottomright0, bottomright1), 0.0, 0.0);
// BottomLeft
QPointF bottomleft0(margin, height - margin);
QPointF bottomleft1(0, height);
gradient.setStart(bottomleft0);
gradient.setFinalStop(bottomleft1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(bottomleft0, bottomleft1), 0.0, 0.0);
// TopLeft
QPointF topleft0(margin, margin);
QPointF topleft1(0, 0);
gradient.setStart(topleft0);
gradient.setFinalStop(topleft1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(topleft0, topleft1), 0.0, 0.0);
// TopRight
QPointF topright0(width - margin, margin);
QPointF topright1(width, 0);
gradient.setStart(topright0);
gradient.setFinalStop(topright1);
gradient.setColorAt(endPosition1, end);
painter.setBrush(QBrush(gradient));
painter.drawRoundedRect(QRectF(topright0, topright1), 0.0, 0.0);
// Widget
painter.setBrush(QBrush("#FFFFFF"));
painter.setRenderHint(QPainter::Antialiasing);
painter.drawRoundedRect(
QRectF(QPointF(margin, margin), QPointF(width - margin, height - margin)),
radius,
radius);
}
}; };

View file

@ -2,6 +2,8 @@
#include <QFontDatabase> #include <QFontDatabase>
#include <QIcon> #include <QIcon>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPaintEvent>
#include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include <QResizeEvent> #include <QResizeEvent>
#include <QSignalTransition> #include <QSignalTransition>

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <QPaintEvent>
#include <QPainter>
#include <QPushButton> #include <QPushButton>
#include <QStateMachine> #include <QStateMachine>

View file

@ -1,3 +1,4 @@
#include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include "FloatingButton.h" #include "FloatingButton.h"

View file

@ -1,7 +1,8 @@
#include "LoadingIndicator.h" #include "LoadingIndicator.h"
#include <QPoint> #include <QPaintEvent>
#include <QtGlobal> #include <QPainter>
#include <QTimer>
LoadingIndicator::LoadingIndicator(QWidget *parent) LoadingIndicator::LoadingIndicator(QWidget *parent)
: QWidget(parent) : QWidget(parent)

View file

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <QColor> #include <QColor>
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>
#include <QWidget> #include <QWidget>
class QPainter;
class QTimer;
class QPaintEvent;
class LoadingIndicator : public QWidget class LoadingIndicator : public QWidget
{ {
Q_OBJECT Q_OBJECT

View file

@ -1,5 +1,7 @@
#include "OverlayWidget.h" #include "OverlayWidget.h"
#include <QEvent>
#include <QPainter>
#include <QStyleOption>
OverlayWidget::OverlayWidget(QWidget *parent) OverlayWidget::OverlayWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <QEvent> #include <QEvent>
#include <QPainter>
#include <QStyleOption>
#include <QWidget> #include <QWidget>
class QPainter;
class OverlayWidget : public QWidget class OverlayWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT