From eae069ad93a6822e8cb96522708115793c01c5d7 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 30 Nov 2017 20:02:46 +0200 Subject: Group emoji and dialogs with namespaces --- CMakeLists.txt | 35 +- include/RoomList.h | 6 +- include/TextInputWidget.h | 4 +- include/TopRoomBar.h | 5 +- include/UserInfoWidget.h | 5 +- include/dialogs/ImageOverlay.h | 49 ++ include/dialogs/ImageOverlayDialog.h | 46 -- include/dialogs/JoinRoom.h | 26 + include/dialogs/JoinRoomDialog.h | 22 - include/dialogs/LeaveRoom.h | 25 + include/dialogs/LeaveRoomDialog.h | 22 - include/dialogs/Logout.h | 42 + include/dialogs/LogoutDialog.h | 39 - include/emoji/Category.h | 60 ++ include/emoji/EmojiCategory.h | 59 -- include/emoji/EmojiItemDelegate.h | 40 - include/emoji/EmojiPanel.h | 55 -- include/emoji/EmojiPickButton.h | 48 -- include/emoji/EmojiProvider.h | 41 - include/emoji/ItemDelegate.h | 43 + include/emoji/Panel.h | 58 ++ include/emoji/PickButton.h | 51 ++ include/emoji/Provider.h | 44 + resources/styles/nheko-dark.qss | 14 +- resources/styles/nheko.qss | 30 +- resources/styles/system.qss | 8 +- src/RoomList.cc | 7 +- src/TextInputWidget.cc | 2 +- src/TopRoomBar.cc | 4 +- src/UserInfoWidget.cc | 4 +- src/dialogs/ImageOverlay.cc | 131 +++ src/dialogs/ImageOverlayDialog.cc | 129 --- src/dialogs/JoinRoom.cc | 51 ++ src/dialogs/JoinRoomDialog.cc | 49 -- src/dialogs/LeaveRoom.cc | 56 ++ src/dialogs/LeaveRoomDialog.cc | 54 -- src/dialogs/Logout.cc | 74 ++ src/dialogs/LogoutDialog.cc | 72 -- src/emoji/Category.cc | 92 +++ src/emoji/EmojiCategory.cc | 90 --- src/emoji/EmojiItemDelegate.cc | 47 -- src/emoji/EmojiPanel.cc | 245 ------ src/emoji/EmojiPickButton.cc | 65 -- src/emoji/EmojiProvider.cc | 1465 --------------------------------- src/emoji/ItemDelegate.cc | 49 ++ src/emoji/Panel.cc | 243 ++++++ src/emoji/PickButton.cc | 66 ++ src/emoji/Provider.cc | 1467 ++++++++++++++++++++++++++++++++++ src/timeline/widgets/ImageItem.cc | 4 +- 49 files changed, 2682 insertions(+), 2661 deletions(-) create mode 100644 include/dialogs/ImageOverlay.h delete mode 100644 include/dialogs/ImageOverlayDialog.h create mode 100644 include/dialogs/JoinRoom.h delete mode 100644 include/dialogs/JoinRoomDialog.h create mode 100644 include/dialogs/LeaveRoom.h delete mode 100644 include/dialogs/LeaveRoomDialog.h create mode 100644 include/dialogs/Logout.h delete mode 100644 include/dialogs/LogoutDialog.h create mode 100644 include/emoji/Category.h delete mode 100644 include/emoji/EmojiCategory.h delete mode 100644 include/emoji/EmojiItemDelegate.h delete mode 100644 include/emoji/EmojiPanel.h delete mode 100644 include/emoji/EmojiPickButton.h delete mode 100644 include/emoji/EmojiProvider.h create mode 100644 include/emoji/ItemDelegate.h create mode 100644 include/emoji/Panel.h create mode 100644 include/emoji/PickButton.h create mode 100644 include/emoji/Provider.h create mode 100644 src/dialogs/ImageOverlay.cc delete mode 100644 src/dialogs/ImageOverlayDialog.cc create mode 100644 src/dialogs/JoinRoom.cc delete mode 100644 src/dialogs/JoinRoomDialog.cc create mode 100644 src/dialogs/LeaveRoom.cc delete mode 100644 src/dialogs/LeaveRoomDialog.cc create mode 100644 src/dialogs/Logout.cc delete mode 100644 src/dialogs/LogoutDialog.cc create mode 100644 src/emoji/Category.cc delete mode 100644 src/emoji/EmojiCategory.cc delete mode 100644 src/emoji/EmojiItemDelegate.cc delete mode 100644 src/emoji/EmojiPanel.cc delete mode 100644 src/emoji/EmojiPickButton.cc delete mode 100644 src/emoji/EmojiProvider.cc create mode 100644 src/emoji/ItemDelegate.cc create mode 100644 src/emoji/Panel.cc create mode 100644 src/emoji/PickButton.cc create mode 100644 src/emoji/Provider.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b13def9..c2d9ff58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,17 +141,17 @@ endif() # set(SRC_FILES # Dialogs - src/dialogs/ImageOverlayDialog.cc - src/dialogs/JoinRoomDialog.cc - src/dialogs/LeaveRoomDialog.cc - src/dialogs/LogoutDialog.cc + src/dialogs/ImageOverlay.cc + src/dialogs/JoinRoom.cc + src/dialogs/LeaveRoom.cc + src/dialogs/Logout.cc # Emoji - src/emoji/EmojiCategory.cc - src/emoji/EmojiItemDelegate.cc - src/emoji/EmojiPanel.cc - src/emoji/EmojiPickButton.cc - src/emoji/EmojiProvider.cc + src/emoji/Category.cc + src/emoji/ItemDelegate.cc + src/emoji/Panel.cc + src/emoji/PickButton.cc + src/emoji/Provider.cc # Timeline src/timeline/TimelineViewManager.cc @@ -245,17 +245,16 @@ include_directories(${LMDB_INCLUDE_DIR}) qt5_wrap_cpp(MOC_HEADERS # Dialogs - include/dialogs/ImageOverlayDialog.h - include/dialogs/JoinRoomDialog.h - include/dialogs/LeaveRoomDialog.h - include/dialogs/LogoutDialog.h + include/dialogs/ImageOverlay.h + include/dialogs/JoinRoom.h + include/dialogs/LeaveRoom.h + include/dialogs/Logout.h # Emoji - include/emoji/EmojiCategory.h - include/emoji/EmojiItemDelegate.h - include/emoji/EmojiPanel.h - include/emoji/EmojiPickButton.h - include/emoji/EmojiProvider.h + include/emoji/Category.h + include/emoji/ItemDelegate.h + include/emoji/Panel.h + include/emoji/PickButton.h # Timeline include/timeline/TimelineItem.h diff --git a/include/RoomList.h b/include/RoomList.h index aa7c919c..f75f7ba4 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -24,7 +24,8 @@ #include #include -class JoinRoomDialog; +#include "dialogs/LeaveRoom.h" + class LeaveRoomDialog; class MatrixClient; class OverlayModal; @@ -82,10 +83,9 @@ private: QPushButton *joinRoomButton_; OverlayModal *joinRoomModal_; - JoinRoomDialog *joinRoomDialog_; QSharedPointer leaveRoomModal_; - QSharedPointer leaveRoomDialog_; + QSharedPointer leaveRoomDialog_; QMap> rooms_; diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index ede7b18a..3c338fe3 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -28,7 +28,7 @@ #include "Image.h" #include "LoadingIndicator.h" -#include "emoji/EmojiPickButton.h" +#include "emoji/PickButton.h" namespace msgs = matrix::events::messages; @@ -107,5 +107,5 @@ private: FlatButton *sendFileBtn_; FlatButton *sendMessageBtn_; - EmojiPickButton *emojiBtn_; + emoji::PickButton *emojiBtn_; }; diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 2f65428d..7bd10356 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -26,10 +26,11 @@ #include #include +#include "dialogs/LeaveRoom.h" + class Avatar; class FlatButton; class Label; -class LeaveRoomDialog; class Menu; class OverlayModal; class RoomSettings; @@ -79,7 +80,7 @@ private: FlatButton *settingsBtn_; QSharedPointer leaveRoomModal_; - QSharedPointer leaveRoomDialog_; + QSharedPointer leaveRoomDialog_; Avatar *avatar_; diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 2acfedb8..3c20380f 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -20,9 +20,10 @@ #include #include +#include "dialogs/Logout.h" + class Avatar; class FlatButton; -class LogoutDialog; class OverlayModal; class UserInfoWidget : public QWidget @@ -68,7 +69,7 @@ private: QImage avatar_image_; QSharedPointer logoutModal_; - QSharedPointer logoutDialog_; + QSharedPointer logoutDialog_; int logoutButtonSize_; }; diff --git a/include/dialogs/ImageOverlay.h b/include/dialogs/ImageOverlay.h new file mode 100644 index 00000000..682999ef --- /dev/null +++ b/include/dialogs/ImageOverlay.h @@ -0,0 +1,49 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace dialogs { + +class ImageOverlay : public QWidget +{ + Q_OBJECT +public: + ImageOverlay(QPixmap image, QWidget *parent = nullptr); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(); + +private: + void scaleImage(int width, int height); + + QPixmap originalImage_; + QPixmap image_; + + QRect content_; + QRect close_button_; + QRect screen_; +}; +} // dialogs diff --git a/include/dialogs/ImageOverlayDialog.h b/include/dialogs/ImageOverlayDialog.h deleted file mode 100644 index 5159c665..00000000 --- a/include/dialogs/ImageOverlayDialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include -#include -#include - -class ImageOverlayDialog : public QWidget -{ - Q_OBJECT -public: - ImageOverlayDialog(QPixmap image, QWidget *parent = nullptr); - -protected: - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; - -signals: - void closing(); - -private: - void scaleImage(int width, int height); - - QPixmap originalImage_; - QPixmap image_; - - QRect content_; - QRect close_button_; - QRect screen_; -}; diff --git a/include/dialogs/JoinRoom.h b/include/dialogs/JoinRoom.h new file mode 100644 index 00000000..dbc06bdf --- /dev/null +++ b/include/dialogs/JoinRoom.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +class FlatButton; + +namespace dialogs { + +class JoinRoom : public QFrame +{ + Q_OBJECT +public: + JoinRoom(QWidget *parent = nullptr); + +signals: + void closing(bool isJoining, QString roomAlias); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; + + QLineEdit *roomAliasEdit_; +}; + +} // dialogs diff --git a/include/dialogs/JoinRoomDialog.h b/include/dialogs/JoinRoomDialog.h deleted file mode 100644 index 84184733..00000000 --- a/include/dialogs/JoinRoomDialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include - -class FlatButton; - -class JoinRoomDialog : public QFrame -{ - Q_OBJECT -public: - JoinRoomDialog(QWidget *parent = nullptr); - -signals: - void closing(bool isJoining, QString roomAlias); - -private: - FlatButton *confirmBtn_; - FlatButton *cancelBtn_; - - QLineEdit *roomAliasEdit_; -}; diff --git a/include/dialogs/LeaveRoom.h b/include/dialogs/LeaveRoom.h new file mode 100644 index 00000000..98e4938d --- /dev/null +++ b/include/dialogs/LeaveRoom.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class FlatButton; + +namespace dialogs { + +class LeaveRoom : public QFrame +{ + Q_OBJECT +public: + explicit LeaveRoom(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(bool isLeaving); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; +}; +} // dialogs diff --git a/include/dialogs/LeaveRoomDialog.h b/include/dialogs/LeaveRoomDialog.h deleted file mode 100644 index eab022f7..00000000 --- a/include/dialogs/LeaveRoomDialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include - -class FlatButton; - -class LeaveRoomDialog : public QFrame -{ - Q_OBJECT -public: - explicit LeaveRoomDialog(QWidget *parent = nullptr); - -protected: - void paintEvent(QPaintEvent *event) override; - -signals: - void closing(bool isLeaving); - -private: - FlatButton *confirmBtn_; - FlatButton *cancelBtn_; -}; diff --git a/include/dialogs/Logout.h b/include/dialogs/Logout.h new file mode 100644 index 00000000..cfefb970 --- /dev/null +++ b/include/dialogs/Logout.h @@ -0,0 +1,42 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include + +class FlatButton; + +namespace dialogs { + +class Logout : public QFrame +{ + Q_OBJECT +public: + explicit Logout(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(bool isLoggingOut); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; +}; +} // dialogs diff --git a/include/dialogs/LogoutDialog.h b/include/dialogs/LogoutDialog.h deleted file mode 100644 index a1a5ee4f..00000000 --- a/include/dialogs/LogoutDialog.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include - -class FlatButton; - -class LogoutDialog : public QFrame -{ - Q_OBJECT -public: - explicit LogoutDialog(QWidget *parent = nullptr); - -protected: - void paintEvent(QPaintEvent *event) override; - -signals: - void closing(bool isLoggingOut); - -private: - FlatButton *confirmBtn_; - FlatButton *cancelBtn_; -}; diff --git a/include/emoji/Category.h b/include/emoji/Category.h new file mode 100644 index 00000000..0310a4f3 --- /dev/null +++ b/include/emoji/Category.h @@ -0,0 +1,60 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +#include "ItemDelegate.h" + +namespace emoji { + +class Category : public QWidget +{ + Q_OBJECT + +public: + Category(QString category, QList emoji, QWidget *parent = nullptr); + ~Category(); + +signals: + void emojiSelected(const QString &emoji); + +protected: + void paintEvent(QPaintEvent *event) override; + +private slots: + void clickIndex(const QModelIndex &index) + { + emit emojiSelected(index.data(Qt::UserRole).toString()); + }; + +private: + QVBoxLayout *mainLayout_; + + QStandardItemModel *itemModel_; + QListView *emojiListView_; + + emoji::Emoji *data_; + emoji::ItemDelegate *delegate_; + + QLabel *category_; +}; +} // namespace emoji diff --git a/include/emoji/EmojiCategory.h b/include/emoji/EmojiCategory.h deleted file mode 100644 index be0110f2..00000000 --- a/include/emoji/EmojiCategory.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include - -#include "EmojiItemDelegate.h" - -class EmojiProvider; - -class EmojiCategory : public QWidget -{ - Q_OBJECT - -public: - EmojiCategory(QString category, QList emoji, QWidget *parent = nullptr); - ~EmojiCategory(); - -signals: - void emojiSelected(const QString &emoji); - -protected: - void paintEvent(QPaintEvent *event) override; - -private slots: - void clickIndex(const QModelIndex &index) - { - emit emojiSelected(index.data(Qt::UserRole).toString()); - }; - -private: - QVBoxLayout *mainLayout_; - - QStandardItemModel *itemModel_; - QListView *emojiListView_; - - Emoji *data_; - EmojiItemDelegate *delegate_; - - QLabel *category_; -}; diff --git a/include/emoji/EmojiItemDelegate.h b/include/emoji/EmojiItemDelegate.h deleted file mode 100644 index 15d61f49..00000000 --- a/include/emoji/EmojiItemDelegate.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include -#include -#include - -#include "EmojiProvider.h" - -class EmojiItemDelegate : public QStyledItemDelegate -{ - Q_OBJECT - -public: - explicit EmojiItemDelegate(QObject *parent = nullptr); - ~EmojiItemDelegate(); - - void paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const override; - -private: - Emoji *data_; -}; diff --git a/include/emoji/EmojiPanel.h b/include/emoji/EmojiPanel.h deleted file mode 100644 index 9eecc8e0..00000000 --- a/include/emoji/EmojiPanel.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include - -#include "EmojiProvider.h" - -class EmojiCategory; - -class EmojiPanel : public QWidget -{ - Q_OBJECT - -public: - EmojiPanel(QWidget *parent = nullptr); - -signals: - void mouseLeft(); - void emojiSelected(const QString &emoji); - -protected: - void leaveEvent(QEvent *event); - void paintEvent(QPaintEvent *event); - -private: - void showEmojiCategory(const EmojiCategory *category); - - EmojiProvider emoji_provider_; - - QScrollArea *scrollArea_; - - int shadowMargin_; - - // Panel dimensions. - int width_; - int height_; - - int categoryIconSize_; -}; diff --git a/include/emoji/EmojiPickButton.h b/include/emoji/EmojiPickButton.h deleted file mode 100644 index 8ef9be9e..00000000 --- a/include/emoji/EmojiPickButton.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include -#include - -#include "FlatButton.h" - -class EmojiPanel; - -class EmojiPickButton : public FlatButton -{ - Q_OBJECT -public: - explicit EmojiPickButton(QWidget *parent = nullptr); - -signals: - void emojiSelected(const QString &emoji); - -protected: - void enterEvent(QEvent *e) override; - void leaveEvent(QEvent *e) override; - -private: - // Vertical distance from panel's bottom. - int vertical_distance_ = 10; - - // Horizontal distance from panel's bottom right corner. - int horizontal_distance_ = 70; - - QSharedPointer panel_; -}; diff --git a/include/emoji/EmojiProvider.h b/include/emoji/EmojiProvider.h deleted file mode 100644 index 847157fd..00000000 --- a/include/emoji/EmojiProvider.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#pragma once - -#include - -struct Emoji -{ - // Unicode code. - QString unicode; - // Keyboard shortcut e.g :emoji: - QString shortname; -}; - -class EmojiProvider -{ -public: - static const QList people; - static const QList nature; - static const QList food; - static const QList activity; - static const QList travel; - static const QList objects; - static const QList symbols; - static const QList flags; -}; diff --git a/include/emoji/ItemDelegate.h b/include/emoji/ItemDelegate.h new file mode 100644 index 00000000..e0456308 --- /dev/null +++ b/include/emoji/ItemDelegate.h @@ -0,0 +1,43 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +#include "Provider.h" + +namespace emoji { + +class ItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + explicit ItemDelegate(QObject *parent = nullptr); + ~ItemDelegate(); + + void paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + +private: + Emoji *data_; +}; +} // namespace emoji diff --git a/include/emoji/Panel.h b/include/emoji/Panel.h new file mode 100644 index 00000000..523a855e --- /dev/null +++ b/include/emoji/Panel.h @@ -0,0 +1,58 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include + +#include "Provider.h" + +namespace emoji { + +class Category; + +class Panel : public QWidget +{ + Q_OBJECT + +public: + Panel(QWidget *parent = nullptr); + +signals: + void mouseLeft(); + void emojiSelected(const QString &emoji); + +protected: + void leaveEvent(QEvent *event); + void paintEvent(QPaintEvent *event); + +private: + void showCategory(const Category *category); + + Provider emoji_provider_; + + QScrollArea *scrollArea_; + + int shadowMargin_; + + // Panel dimensions. + int width_; + int height_; + + int categoryIconSize_; +}; +} // namespace emoji diff --git a/include/emoji/PickButton.h b/include/emoji/PickButton.h new file mode 100644 index 00000000..d0026828 --- /dev/null +++ b/include/emoji/PickButton.h @@ -0,0 +1,51 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include +#include + +#include "FlatButton.h" + +namespace emoji { + +class Panel; + +class PickButton : public FlatButton +{ + Q_OBJECT +public: + explicit PickButton(QWidget *parent = nullptr); + +signals: + void emojiSelected(const QString &emoji); + +protected: + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + +private: + // Vertical distance from panel's bottom. + int vertical_distance_ = 10; + + // Horizontal distance from panel's bottom right corner. + int horizontal_distance_ = 70; + + QSharedPointer panel_; +}; +} // namespace emoji diff --git a/include/emoji/Provider.h b/include/emoji/Provider.h new file mode 100644 index 00000000..8754dabc --- /dev/null +++ b/include/emoji/Provider.h @@ -0,0 +1,44 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include + +namespace emoji { + +struct Emoji +{ + // Unicode code. + QString unicode; + // Keyboard shortcut e.g :emoji: + QString shortname; +}; + +class Provider +{ +public: + static const QList people; + static const QList nature; + static const QList food; + static const QList activity; + static const QList travel; + static const QList objects; + static const QList symbols; + static const QList flags; +}; +} // namespace emoji diff --git a/resources/styles/nheko-dark.qss b/resources/styles/nheko-dark.qss index 1a32ced3..0182d7a3 100644 --- a/resources/styles/nheko-dark.qss +++ b/resources/styles/nheko-dark.qss @@ -71,8 +71,8 @@ Avatar { color: #f2f2f2; } -LogoutDialog, -LeaveRoomDialog { +dialogs--Logout, +dialogs--LeaveRoom { background-color: #383c4a; color: #caccd1; } @@ -84,14 +84,14 @@ RegisterPage { color: #caccd1; } -EmojiPanel, -EmojiPanel > * { - background-color: #383c4a; +emoji--Panel, +emoji--Panel > * { + background-color: #313440; color: #caccd1; } -EmojiCategory, -EmojiCategory > * { +emoji--Category, +emoji--Category > * { background-color: #383c4a; color: #caccd1; } diff --git a/resources/styles/nheko.qss b/resources/styles/nheko.qss index 3e889530..4251b4a5 100644 --- a/resources/styles/nheko.qss +++ b/resources/styles/nheko.qss @@ -73,39 +73,27 @@ Avatar { color: #555459; } -LogoutDialog { - background-color: white; - color: #333; -} - -LeaveRoomDialog { - background-color: white; - color: #333; -} - -WelcomePage { - background-color: white; - color: #333; -} - -LoginPage { +dialogs--Logout, +dialogs--LeaveRoom { background-color: white; color: #333; } +WelcomePage, +LoginPage, RegisterPage { background-color: white; color: #333; } -EmojiPanel, -EmojiPanel > * { - background-color: white; +emoji--Panel, +emoji--Panel > * { + background-color: #eee; color: #333; } -EmojiCategory, -EmojiCategory > * { +emoji--Category, +emoji--Category > * { background-color: white; color: #ccc; } diff --git a/resources/styles/system.qss b/resources/styles/system.qss index bce0f059..4cd1bbfe 100644 --- a/resources/styles/system.qss +++ b/resources/styles/system.qss @@ -64,13 +64,13 @@ UserInfoWidget > * { background-color: palette(window); } -EmojiCategory, -EmojiCategory > * { +emoji--Category, +emoji--Category > * { background-color: palette(window); } -EmojiPanel, -EmojiPanel > * { +emoji--Panel, +emoji--Panel > * { background-color: palette(window); } diff --git a/src/RoomList.cc b/src/RoomList.cc index 6b8867f3..23c0c5a7 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -18,9 +18,6 @@ #include #include -#include "dialogs/JoinRoomDialog.h" -#include "dialogs/LeaveRoomDialog.h" - #include "MainWindow.h" #include "MatrixClient.h" #include "OverlayModal.h" @@ -159,10 +156,10 @@ void RoomList::openLeaveRoomDialog(const QString &room_id) { if (leaveRoomDialog_.isNull()) { - leaveRoomDialog_ = QSharedPointer(new LeaveRoomDialog(this)); + leaveRoomDialog_ = QSharedPointer(new dialogs::LeaveRoom(this)); connect(leaveRoomDialog_.data(), - &LeaveRoomDialog::closing, + &dialogs::LeaveRoom::closing, this, [=](bool leaving) { closeLeaveRoomDialog(leaving, room_id); }); } diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index c4d01357..2f6c435a 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -211,7 +211,7 @@ TextInputWidget::TextInputWidget(QWidget *parent) sendMessageBtn_->setIcon(send_message_icon); sendMessageBtn_->setIconSize(QSize(24, 24)); - emojiBtn_ = new EmojiPickButton(this); + emojiBtn_ = new emoji::PickButton(this); QIcon emoji_icon; emoji_icon.addFile(":/icons/icons/ui/smile.png"); diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index 3418e6f1..51a3af68 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -27,8 +27,6 @@ #include "RoomSettings.h" #include "TopRoomBar.h" -#include "dialogs/LeaveRoomDialog.h" - TopRoomBar::TopRoomBar(QWidget *parent) : QWidget(parent) , buttonSize_{32} @@ -94,7 +92,7 @@ TopRoomBar::TopRoomBar(QWidget *parent) connect(leaveRoom_, &QAction::triggered, this, [=]() { if (leaveRoomDialog_.isNull()) { leaveRoomDialog_ = - QSharedPointer(new LeaveRoomDialog(this)); + QSharedPointer(new dialogs::LeaveRoom(this)); connect(leaveRoomDialog_.data(), SIGNAL(closing(bool)), diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index 98977bb3..fe0c2b56 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -24,8 +24,6 @@ #include "OverlayModal.h" #include "UserInfoWidget.h" -#include "dialogs/LogoutDialog.h" - UserInfoWidget::UserInfoWidget(QWidget *parent) : QWidget(parent) , display_name_("User") @@ -94,7 +92,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) // Show the confirmation dialog. connect(logoutButton_, &QPushButton::clicked, this, [=]() { if (logoutDialog_.isNull()) { - logoutDialog_ = QSharedPointer(new LogoutDialog(this)); + logoutDialog_ = QSharedPointer(new dialogs::Logout(this)); connect(logoutDialog_.data(), SIGNAL(closing(bool)), this, diff --git a/src/dialogs/ImageOverlay.cc b/src/dialogs/ImageOverlay.cc new file mode 100644 index 00000000..1e30b3ff --- /dev/null +++ b/src/dialogs/ImageOverlay.cc @@ -0,0 +1,131 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#include +#include +#include + +#include "dialogs/ImageOverlay.h" + +using namespace dialogs; + +ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) + : QWidget{parent} + , originalImage_{image} +{ + setMouseTracking(true); + setParent(0); + + setWindowFlags(windowFlags() | Qt::FramelessWindowHint); + + setAttribute(Qt::WA_NoSystemBackground, true); + setAttribute(Qt::WA_TranslucentBackground, true); + setAttribute(Qt::WA_DeleteOnClose, true); + setWindowState(Qt::WindowFullScreen); + + screen_ = QApplication::desktop()->availableGeometry(); + + move(QApplication::desktop()->mapToGlobal(screen_.topLeft())); + resize(screen_.size()); + + connect(this, SIGNAL(closing()), this, SLOT(close())); + + raise(); +} + +// TODO: Move this into Utils +void +ImageOverlay::scaleImage(int max_width, int max_height) +{ + if (originalImage_.isNull()) + return; + + auto width_ratio = (double)max_width / (double)originalImage_.width(); + auto height_ratio = (double)max_height / (double)originalImage_.height(); + + auto min_aspect_ratio = std::min(width_ratio, height_ratio); + + int final_width = 0; + int final_height = 0; + + if (min_aspect_ratio > 1) { + final_width = originalImage_.width(); + final_height = originalImage_.height(); + } else { + final_width = originalImage_.width() * min_aspect_ratio; + final_height = originalImage_.height() * min_aspect_ratio; + } + + image_ = originalImage_.scaled( + final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +} + +void +ImageOverlay::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Full screen overlay. + painter.fillRect(QRect(0, 0, screen_.width(), screen_.height()), QColor(55, 55, 55, 170)); + + // Left and Right margins + int outer_margin = screen_.width() * 0.12; + int buttonSize = 36; + int margin = outer_margin * 0.1; + + int max_width = screen_.width() - 2 * outer_margin; + int max_height = screen_.height(); + + scaleImage(max_width, max_height); + + int diff_x = max_width - image_.width(); + int diff_y = max_height - image_.height(); + + content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height()); + close_button_ = + QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize); + + // Draw main content_. + painter.drawPixmap(content_, image_); + + // Draw top right corner X. + QPen pen; + pen.setCapStyle(Qt::RoundCap); + pen.setWidthF(5); + pen.setColor("gray"); + + auto center = close_button_.center(); + + painter.setPen(pen); + painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15)); + painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15)); +} + +void +ImageOverlay::mousePressEvent(QMouseEvent *event) +{ + if (event->button() != Qt::LeftButton) + return; + + if (close_button_.contains(event->pos())) + emit closing(); + else if (!content_.contains(event->pos())) + emit closing(); +} diff --git a/src/dialogs/ImageOverlayDialog.cc b/src/dialogs/ImageOverlayDialog.cc deleted file mode 100644 index ad87d144..00000000 --- a/src/dialogs/ImageOverlayDialog.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#include -#include -#include - -#include "dialogs/ImageOverlayDialog.h" - -ImageOverlayDialog::ImageOverlayDialog(QPixmap image, QWidget *parent) - : QWidget{parent} - , originalImage_{image} -{ - setMouseTracking(true); - setParent(0); - - setWindowFlags(windowFlags() | Qt::FramelessWindowHint); - - setAttribute(Qt::WA_NoSystemBackground, true); - setAttribute(Qt::WA_TranslucentBackground, true); - setAttribute(Qt::WA_DeleteOnClose, true); - setWindowState(Qt::WindowFullScreen); - - screen_ = QApplication::desktop()->availableGeometry(); - - move(QApplication::desktop()->mapToGlobal(screen_.topLeft())); - resize(screen_.size()); - - connect(this, SIGNAL(closing()), this, SLOT(close())); - - raise(); -} - -// TODO: Move this into Utils -void -ImageOverlayDialog::scaleImage(int max_width, int max_height) -{ - if (originalImage_.isNull()) - return; - - auto width_ratio = (double)max_width / (double)originalImage_.width(); - auto height_ratio = (double)max_height / (double)originalImage_.height(); - - auto min_aspect_ratio = std::min(width_ratio, height_ratio); - - int final_width = 0; - int final_height = 0; - - if (min_aspect_ratio > 1) { - final_width = originalImage_.width(); - final_height = originalImage_.height(); - } else { - final_width = originalImage_.width() * min_aspect_ratio; - final_height = originalImage_.height() * min_aspect_ratio; - } - - image_ = originalImage_.scaled( - final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); -} - -void -ImageOverlayDialog::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - // Full screen overlay. - painter.fillRect(QRect(0, 0, screen_.width(), screen_.height()), QColor(55, 55, 55, 170)); - - // Left and Right margins - int outer_margin = screen_.width() * 0.12; - int buttonSize = 36; - int margin = outer_margin * 0.1; - - int max_width = screen_.width() - 2 * outer_margin; - int max_height = screen_.height(); - - scaleImage(max_width, max_height); - - int diff_x = max_width - image_.width(); - int diff_y = max_height - image_.height(); - - content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height()); - close_button_ = - QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize); - - // Draw main content_. - painter.drawPixmap(content_, image_); - - // Draw top right corner X. - QPen pen; - pen.setCapStyle(Qt::RoundCap); - pen.setWidthF(5); - pen.setColor("gray"); - - auto center = close_button_.center(); - - painter.setPen(pen); - painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15)); - painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15)); -} - -void -ImageOverlayDialog::mousePressEvent(QMouseEvent *event) -{ - if (event->button() != Qt::LeftButton) - return; - - if (close_button_.contains(event->pos())) - emit closing(); - else if (!content_.contains(event->pos())) - emit closing(); -} diff --git a/src/dialogs/JoinRoom.cc b/src/dialogs/JoinRoom.cc new file mode 100644 index 00000000..5b874011 --- /dev/null +++ b/src/dialogs/JoinRoom.cc @@ -0,0 +1,51 @@ +#include +#include + +#include "Config.h" +#include "FlatButton.h" +#include "Theme.h" + +#include "dialogs/JoinRoom.h" + +using namespace dialogs; + +JoinRoom::JoinRoom(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("JOIN", this); + confirmBtn_->setFontSize(conf::btn::fontSize); + + cancelBtn_ = new FlatButton(tr("CANCEL"), this); + cancelBtn_->setFontSize(conf::btn::fontSize); + + buttonLayout->addStretch(1); + buttonLayout->addWidget(confirmBtn_); + buttonLayout->addWidget(cancelBtn_); + + QFont font; + font.setPixelSize(conf::headerFontSize); + + auto label = new QLabel(tr("Room alias to join:"), this); + label->setFont(font); + + roomAliasEdit_ = new QLineEdit(this); + + layout->addWidget(label); + layout->addWidget(roomAliasEdit_); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [=]() { + emit closing(true, roomAliasEdit_->text()); + }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false, nullptr); }); +} diff --git a/src/dialogs/JoinRoomDialog.cc b/src/dialogs/JoinRoomDialog.cc deleted file mode 100644 index 2cee7ef6..00000000 --- a/src/dialogs/JoinRoomDialog.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/JoinRoomDialog.h" - -JoinRoomDialog::JoinRoomDialog(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("JOIN", this); - confirmBtn_->setFontSize(conf::btn::fontSize); - - cancelBtn_ = new FlatButton(tr("CANCEL"), this); - cancelBtn_->setFontSize(conf::btn::fontSize); - - buttonLayout->addStretch(1); - buttonLayout->addWidget(confirmBtn_); - buttonLayout->addWidget(cancelBtn_); - - QFont font; - font.setPixelSize(conf::headerFontSize); - - auto label = new QLabel(tr("Room alias to join:"), this); - label->setFont(font); - - roomAliasEdit_ = new QLineEdit(this); - - layout->addWidget(label); - layout->addWidget(roomAliasEdit_); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [=]() { - emit closing(true, roomAliasEdit_->text()); - }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false, nullptr); }); -} diff --git a/src/dialogs/LeaveRoom.cc b/src/dialogs/LeaveRoom.cc new file mode 100644 index 00000000..6a8447d4 --- /dev/null +++ b/src/dialogs/LeaveRoom.cc @@ -0,0 +1,56 @@ +#include +#include +#include + +#include "Config.h" +#include "FlatButton.h" +#include "Theme.h" + +#include "dialogs/LeaveRoom.h" + +using namespace dialogs; + +LeaveRoom::LeaveRoom(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("LEAVE", this); + confirmBtn_->setFontSize(conf::btn::fontSize); + + cancelBtn_ = new FlatButton(tr("CANCEL"), this); + cancelBtn_->setFontSize(conf::btn::fontSize); + + buttonLayout->addStretch(1); + buttonLayout->addWidget(confirmBtn_); + buttonLayout->addWidget(cancelBtn_); + + QFont font; + font.setPixelSize(conf::headerFontSize); + + auto label = new QLabel(tr("Are you sure you want to leave?"), this); + label->setFont(font); + + layout->addWidget(label); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [=]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); +} + +void +LeaveRoom::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/dialogs/LeaveRoomDialog.cc b/src/dialogs/LeaveRoomDialog.cc deleted file mode 100644 index b0d1679f..00000000 --- a/src/dialogs/LeaveRoomDialog.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/LeaveRoomDialog.h" - -LeaveRoomDialog::LeaveRoomDialog(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("LEAVE", this); - confirmBtn_->setFontSize(conf::btn::fontSize); - - cancelBtn_ = new FlatButton(tr("CANCEL"), this); - cancelBtn_->setFontSize(conf::btn::fontSize); - - buttonLayout->addStretch(1); - buttonLayout->addWidget(confirmBtn_); - buttonLayout->addWidget(cancelBtn_); - - QFont font; - font.setPixelSize(conf::headerFontSize); - - auto label = new QLabel(tr("Are you sure you want to leave?"), this); - label->setFont(font); - - layout->addWidget(label); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [=]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); -} - -void -LeaveRoomDialog::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/dialogs/Logout.cc b/src/dialogs/Logout.cc new file mode 100644 index 00000000..f4752b0a --- /dev/null +++ b/src/dialogs/Logout.cc @@ -0,0 +1,74 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#include +#include +#include +#include + +#include "Config.h" +#include "FlatButton.h" +#include "Theme.h" + +#include "dialogs/Logout.h" + +using namespace dialogs; + +Logout::Logout(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("OK", this); + confirmBtn_->setFontSize(conf::btn::fontSize); + + cancelBtn_ = new FlatButton(tr("CANCEL"), this); + cancelBtn_->setFontSize(conf::btn::fontSize); + + buttonLayout->addStretch(1); + buttonLayout->addWidget(confirmBtn_); + buttonLayout->addWidget(cancelBtn_); + + QFont font; + font.setPixelSize(conf::headerFontSize); + + auto label = new QLabel(tr("Logout. Are you sure?"), this); + label->setFont(font); + + layout->addWidget(label); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [=]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); +} + +void +Logout::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/dialogs/LogoutDialog.cc b/src/dialogs/LogoutDialog.cc deleted file mode 100644 index 73e09745..00000000 --- a/src/dialogs/LogoutDialog.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#include -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/LogoutDialog.h" - -LogoutDialog::LogoutDialog(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("OK", this); - confirmBtn_->setFontSize(conf::btn::fontSize); - - cancelBtn_ = new FlatButton(tr("CANCEL"), this); - cancelBtn_->setFontSize(conf::btn::fontSize); - - buttonLayout->addStretch(1); - buttonLayout->addWidget(confirmBtn_); - buttonLayout->addWidget(cancelBtn_); - - QFont font; - font.setPixelSize(conf::headerFontSize); - - auto label = new QLabel(tr("Logout. Are you sure?"), this); - label->setFont(font); - - layout->addWidget(label); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [=]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); -} - -void -LogoutDialog::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/emoji/Category.cc b/src/emoji/Category.cc new file mode 100644 index 00000000..6b925ce9 --- /dev/null +++ b/src/emoji/Category.cc @@ -0,0 +1,92 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#include +#include +#include + +#include "Config.h" + +#include "emoji/Category.h" + +using namespace emoji; + +Category::Category(QString category, QList emoji, QWidget *parent) + : QWidget(parent) +{ + mainLayout_ = new QVBoxLayout(this); + mainLayout_->setMargin(0); + mainLayout_->setSpacing(0); + + emojiListView_ = new QListView(); + itemModel_ = new QStandardItemModel(this); + + delegate_ = new ItemDelegate(this); + data_ = new Emoji; + + emojiListView_->setItemDelegate(delegate_); + emojiListView_->setModel(itemModel_); + emojiListView_->setViewMode(QListView::IconMode); + emojiListView_->setFlow(QListView::LeftToRight); + emojiListView_->setResizeMode(QListView::Adjust); + emojiListView_->verticalScrollBar()->setEnabled(false); + emojiListView_->horizontalScrollBar()->setEnabled(false); + + const int cols = 7; + const int rows = emoji.size() / 7; + + // TODO: Be precise here. Take the parent into consideration. + emojiListView_->setFixedSize(cols * 50 + 20, rows * 50 + 20); + emojiListView_->setGridSize(QSize(50, 50)); + emojiListView_->setDragEnabled(false); + emojiListView_->setEditTriggers(QAbstractItemView::NoEditTriggers); + + for (const auto &e : emoji) { + data_->unicode = e.unicode; + + auto item = new QStandardItem; + item->setSizeHint(QSize(24, 24)); + + QVariant unicode(data_->unicode); + item->setData(unicode.toString(), Qt::UserRole); + + itemModel_->appendRow(item); + } + + QFont font("Open Sans SemiBold"); + font.setPixelSize(conf::fontSize); + + category_ = new QLabel(category, this); + category_->setFont(font); + category_->setStyleSheet("margin: 20px 0 20px 8px;"); + + mainLayout_->addWidget(category_); + mainLayout_->addWidget(emojiListView_); + + connect(emojiListView_, &QListView::clicked, this, &Category::clickIndex); +} + +void +Category::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + +Category::~Category() {} diff --git a/src/emoji/EmojiCategory.cc b/src/emoji/EmojiCategory.cc deleted file mode 100644 index 42f09409..00000000 --- a/src/emoji/EmojiCategory.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -#include -#include -#include - -#include "Config.h" - -#include "emoji/EmojiCategory.h" - -EmojiCategory::EmojiCategory(QString category, QList emoji, QWidget *parent) - : QWidget(parent) -{ - mainLayout_ = new QVBoxLayout(this); - mainLayout_->setMargin(0); - mainLayout_->setSpacing(0); - - emojiListView_ = new QListView(); - itemModel_ = new QStandardItemModel(this); - - delegate_ = new EmojiItemDelegate(this); - data_ = new Emoji; - - emojiListView_->setItemDelegate(delegate_); - emojiListView_->setModel(itemModel_); - emojiListView_->setViewMode(QListView::IconMode); - emojiListView_->setFlow(QListView::LeftToRight); - emojiListView_->setResizeMode(QListView::Adjust); - emojiListView_->verticalScrollBar()->setEnabled(false); - emojiListView_->horizontalScrollBar()->setEnabled(false); - - const int cols = 7; - const int rows = emoji.size() / 7; - - // TODO: Be precise here. Take the parent into consideration. - emojiListView_->setFixedSize(cols * 50 + 20, rows * 50 + 20); - emojiListView_->setGridSize(QSize(50, 50)); - emojiListView_->setDragEnabled(false); - emojiListView_->setEditTriggers(QAbstractItemView::NoEditTriggers); - - for (const auto &e : emoji) { - data_->unicode = e.unicode; - - auto item = new QStandardItem; - item->setSizeHint(QSize(24, 24)); - - QVariant unicode(data_->unicode); - item->setData(unicode.toString(), Qt::UserRole); - - itemModel_->appendRow(item); - } - - QFont font("Open Sans SemiBold"); - font.setPixelSize(conf::fontSize); - - category_ = new QLabel(category, this); - category_->setFont(font); - category_->setStyleSheet("margin: 20px 0 20px 8px;"); - - mainLayout_->addWidget(category_); - mainLayout_->addWidget(emojiListView_); - - connect(emojiListView_, &QListView::clicked, this, &EmojiCategory::clickIndex); -} - -void -EmojiCategory::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} - -EmojiCategory::~EmojiCategory() {} diff --git a/src/emoji/EmojiItemDelegate.cc b/src/emoji/EmojiItemDelegate.cc deleted file mode 1