matrixion/include/dialogs/RoomSettings.hpp

127 lines
2.7 KiB
C++
Raw Normal View History

2018-04-30 21:41:47 +03:00
#pragma once
#include <QFrame>
#include <QImage>
#include "Cache.h"
class Avatar;
2018-04-30 21:41:47 +03:00
class FlatButton;
class QComboBox;
class QHBoxLayout;
2018-04-30 21:41:47 +03:00
class QLabel;
class QLabel;
class QLayout;
class QPixmap;
class TextField;
class TextField;
class Toggle;
2018-04-30 21:41:47 +03:00
template<class T>
class QSharedPointer;
class EditModal : public QWidget
{
Q_OBJECT
public:
EditModal(const QString &roomId, QWidget *parent = nullptr);
void setFields(const QString &roomName, const QString &roomTopic);
signals:
void nameChanged(const QString &roomName);
void nameEventSentCb(const QString &newName);
void topicEventSentCb();
void stateEventErrorCb(const QString &msg);
private:
QString roomId_;
QString initialName_;
QString initialTopic_;
QLabel *errorField_;
TextField *nameInput_;
TextField *topicInput_;
FlatButton *applyBtn_;
FlatButton *cancelBtn_;
};
2018-04-30 21:41:47 +03:00
class TopSection : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
public:
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr);
QSize sizeHint() const override;
void setRoomName(const QString &name);
2018-04-30 21:41:47 +03:00
QColor textColor() const { return textColor_; }
void setTextColor(QColor &color) { textColor_ = color; }
protected:
void paintEvent(QPaintEvent *event) override;
private:
static constexpr int AvatarSize = 72;
static constexpr int Padding = 5;
RoomInfo info_;
QPixmap avatar_;
QColor textColor_;
};
namespace dialogs {
class RoomSettings : public QFrame
{
Q_OBJECT
public:
2018-05-08 20:30:09 +03:00
RoomSettings(const QString &room_id, QWidget *parent = nullptr);
2018-04-30 21:41:47 +03:00
signals:
void closing();
void enableEncryptionError(const QString &msg);
2018-04-30 21:41:47 +03:00
protected:
void paintEvent(QPaintEvent *event) override;
private slots:
void saveSettings();
2018-04-30 21:41:47 +03:00
private:
static constexpr int AvatarSize = 64;
void setAvatar(const QImage &img) { avatarImg_ = img; }
void setupEditButton();
//! Retrieve the current room information from cache.
void retrieveRoomInfo();
void enableEncryption();
//! Whether the user would be able to change the name or the topic of the room.
bool hasEditRights_ = true;
bool usesEncryption_ = false;
QHBoxLayout *editLayout_;
2018-04-30 21:41:47 +03:00
// Button section
FlatButton *okBtn_;
2018-04-30 21:41:47 +03:00
FlatButton *cancelBtn_;
FlatButton *editFieldsBtn_;
2018-04-30 21:41:47 +03:00
RoomInfo info_;
QString room_id_;
QImage avatarImg_;
TopSection *topSection_;
QComboBox *accessCombo;
Toggle *encryptionToggle_;
2018-04-30 21:41:47 +03:00
};
} // dialogs