Change indentation to 4 spaces
This commit is contained in:
parent
e118f3882d
commit
cfca7157b9
165 changed files with 23146 additions and 23975 deletions
|
|
@ -18,142 +18,142 @@ using namespace dialogs;
|
|||
CreateRoom::CreateRoom(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
QFont largeFont;
|
||||
largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5);
|
||||
QFont largeFont;
|
||||
largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5);
|
||||
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
setMinimumHeight(conf::modals::MIN_WIDGET_HEIGHT);
|
||||
setMinimumWidth(conf::window::minModalWidth);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
setMinimumHeight(conf::modals::MIN_WIDGET_HEIGHT);
|
||||
setMinimumWidth(conf::window::minModalWidth);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(15);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(15);
|
||||
|
||||
confirmBtn_ = new QPushButton(tr("Create room"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Create room"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * 1.3);
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * 1.3);
|
||||
|
||||
nameInput_ = new TextField(this);
|
||||
nameInput_->setLabel(tr("Name"));
|
||||
nameInput_ = new TextField(this);
|
||||
nameInput_->setLabel(tr("Name"));
|
||||
|
||||
topicInput_ = new TextField(this);
|
||||
topicInput_->setLabel(tr("Topic"));
|
||||
topicInput_ = new TextField(this);
|
||||
topicInput_->setLabel(tr("Topic"));
|
||||
|
||||
aliasInput_ = new TextField(this);
|
||||
aliasInput_->setLabel(tr("Alias"));
|
||||
aliasInput_ = new TextField(this);
|
||||
aliasInput_->setLabel(tr("Alias"));
|
||||
|
||||
auto visibilityLayout = new QHBoxLayout;
|
||||
visibilityLayout->setContentsMargins(0, 10, 0, 10);
|
||||
auto visibilityLayout = new QHBoxLayout;
|
||||
visibilityLayout->setContentsMargins(0, 10, 0, 10);
|
||||
|
||||
auto presetLayout = new QHBoxLayout;
|
||||
presetLayout->setContentsMargins(0, 10, 0, 10);
|
||||
auto presetLayout = new QHBoxLayout;
|
||||
presetLayout->setContentsMargins(0, 10, 0, 10);
|
||||
|
||||
auto visibilityLabel = new QLabel(tr("Room Visibility"), this);
|
||||
visibilityCombo_ = new QComboBox(this);
|
||||
visibilityCombo_->addItem("Private");
|
||||
visibilityCombo_->addItem("Public");
|
||||
auto visibilityLabel = new QLabel(tr("Room Visibility"), this);
|
||||
visibilityCombo_ = new QComboBox(this);
|
||||
visibilityCombo_->addItem("Private");
|
||||
visibilityCombo_->addItem("Public");
|
||||
|
||||
visibilityLayout->addWidget(visibilityLabel);
|
||||
visibilityLayout->addWidget(visibilityCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
visibilityLayout->addWidget(visibilityLabel);
|
||||
visibilityLayout->addWidget(visibilityCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
|
||||
auto presetLabel = new QLabel(tr("Room Preset"), this);
|
||||
presetCombo_ = new QComboBox(this);
|
||||
presetCombo_->addItem("Private Chat");
|
||||
presetCombo_->addItem("Public Chat");
|
||||
presetCombo_->addItem("Trusted Private Chat");
|
||||
auto presetLabel = new QLabel(tr("Room Preset"), this);
|
||||
presetCombo_ = new QComboBox(this);
|
||||
presetCombo_->addItem("Private Chat");
|
||||
presetCombo_->addItem("Public Chat");
|
||||
presetCombo_->addItem("Trusted Private Chat");
|
||||
|
||||
presetLayout->addWidget(presetLabel);
|
||||
presetLayout->addWidget(presetCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
presetLayout->addWidget(presetLabel);
|
||||
presetLayout->addWidget(presetCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
|
||||
auto directLabel_ = new QLabel(tr("Direct Chat"), this);
|
||||
directToggle_ = new Toggle(this);
|
||||
directToggle_->setActiveColor(QColor("#38A3D8"));
|
||||
directToggle_->setInactiveColor(QColor("gray"));
|
||||
directToggle_->setState(false);
|
||||
auto directLabel_ = new QLabel(tr("Direct Chat"), this);
|
||||
directToggle_ = new Toggle(this);
|
||||
directToggle_->setActiveColor(QColor("#38A3D8"));
|
||||
directToggle_->setInactiveColor(QColor("gray"));
|
||||
directToggle_->setState(false);
|
||||
|
||||
auto directLayout = new QHBoxLayout;
|
||||
directLayout->setContentsMargins(0, 10, 0, 10);
|
||||
directLayout->addWidget(directLabel_);
|
||||
directLayout->addWidget(directToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
auto directLayout = new QHBoxLayout;
|
||||
directLayout->setContentsMargins(0, 10, 0, 10);
|
||||
directLayout->addWidget(directLabel_);
|
||||
directLayout->addWidget(directToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
|
||||
layout->addWidget(nameInput_);
|
||||
layout->addWidget(topicInput_);
|
||||
layout->addWidget(aliasInput_);
|
||||
layout->addLayout(visibilityLayout);
|
||||
layout->addLayout(presetLayout);
|
||||
layout->addLayout(directLayout);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addWidget(nameInput_);
|
||||
layout->addWidget(topicInput_);
|
||||
layout->addWidget(aliasInput_);
|
||||
layout->addLayout(visibilityLayout);
|
||||
layout->addLayout(presetLayout);
|
||||
layout->addLayout(directLayout);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
request_.name = nameInput_->text().toStdString();
|
||||
request_.topic = topicInput_->text().toStdString();
|
||||
request_.room_alias_name = aliasInput_->text().toStdString();
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
request_.name = nameInput_->text().toStdString();
|
||||
request_.topic = topicInput_->text().toStdString();
|
||||
request_.room_alias_name = aliasInput_->text().toStdString();
|
||||
|
||||
emit createRoom(request_);
|
||||
emit createRoom(request_);
|
||||
|
||||
clearFields();
|
||||
emit close();
|
||||
});
|
||||
clearFields();
|
||||
emit close();
|
||||
});
|
||||
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
clearFields();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
clearFields();
|
||||
emit close();
|
||||
});
|
||||
|
||||
connect(visibilityCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||
[this](const QString &text) {
|
||||
if (text == "Private") {
|
||||
request_.visibility = mtx::common::RoomVisibility::Private;
|
||||
} else {
|
||||
request_.visibility = mtx::common::RoomVisibility::Public;
|
||||
}
|
||||
});
|
||||
connect(visibilityCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||
[this](const QString &text) {
|
||||
if (text == "Private") {
|
||||
request_.visibility = mtx::common::RoomVisibility::Private;
|
||||
} else {
|
||||
request_.visibility = mtx::common::RoomVisibility::Public;
|
||||
}
|
||||
});
|
||||
|
||||
connect(presetCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||
[this](const QString &text) {
|
||||
if (text == "Private Chat") {
|
||||
request_.preset = mtx::requests::Preset::PrivateChat;
|
||||
} else if (text == "Public Chat") {
|
||||
request_.preset = mtx::requests::Preset::PublicChat;
|
||||
} else {
|
||||
request_.preset = mtx::requests::Preset::TrustedPrivateChat;
|
||||
}
|
||||
});
|
||||
connect(presetCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||
[this](const QString &text) {
|
||||
if (text == "Private Chat") {
|
||||
request_.preset = mtx::requests::Preset::PrivateChat;
|
||||
} else if (text == "Public Chat") {
|
||||
request_.preset = mtx::requests::Preset::PublicChat;
|
||||
} else {
|
||||
request_.preset = mtx::requests::Preset::TrustedPrivateChat;
|
||||
}
|
||||
});
|
||||
|
||||
connect(directToggle_, &Toggle::toggled, this, [this](bool isEnabled) {
|
||||
request_.is_direct = isEnabled;
|
||||
});
|
||||
connect(directToggle_, &Toggle::toggled, this, [this](bool isEnabled) {
|
||||
request_.is_direct = isEnabled;
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
CreateRoom::clearFields()
|
||||
{
|
||||
nameInput_->clear();
|
||||
topicInput_->clear();
|
||||
aliasInput_->clear();
|
||||
nameInput_->clear();
|
||||
topicInput_->clear();
|
||||
aliasInput_->clear();
|
||||
}
|
||||
|
||||
void
|
||||
CreateRoom::showEvent(QShowEvent *event)
|
||||
{
|
||||
nameInput_->setFocus();
|
||||
nameInput_->setFocus();
|
||||
|
||||
QFrame::showEvent(event);
|
||||
QFrame::showEvent(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,32 +17,32 @@ namespace dialogs {
|
|||
|
||||
class CreateRoom : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
CreateRoom(QWidget *parent = nullptr);
|
||||
CreateRoom(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void createRoom(const mtx::requests::CreateRoom &request);
|
||||
void createRoom(const mtx::requests::CreateRoom &request);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
void clearFields();
|
||||
void clearFields();
|
||||
|
||||
QComboBox *visibilityCombo_;
|
||||
QComboBox *presetCombo_;
|
||||
QComboBox *visibilityCombo_;
|
||||
QComboBox *presetCombo_;
|
||||
|
||||
Toggle *directToggle_;
|
||||
Toggle *directToggle_;
|
||||
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
|
||||
TextField *nameInput_;
|
||||
TextField *topicInput_;
|
||||
TextField *aliasInput_;
|
||||
TextField *nameInput_;
|
||||
TextField *topicInput_;
|
||||
TextField *aliasInput_;
|
||||
|
||||
mtx::requests::CreateRoom request_;
|
||||
mtx::requests::CreateRoom request_;
|
||||
};
|
||||
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -18,56 +18,56 @@ using namespace dialogs;
|
|||
FallbackAuth::FallbackAuth(const QString &authType, const QString &session, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(8);
|
||||
buttonLayout->setMargin(0);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(8);
|
||||
buttonLayout->setMargin(0);
|
||||
|
||||
openBtn_ = new QPushButton(tr("Open Fallback in Browser"), this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Confirm"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
openBtn_ = new QPushButton(tr("Open Fallback in Browser"), this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Confirm"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(openBtn_);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(openBtn_);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
|
||||
auto label = new QLabel(
|
||||
tr("Open the fallback, follow the steps and confirm after completing them."), this);
|
||||
label->setFont(font);
|
||||
auto label = new QLabel(
|
||||
tr("Open the fallback, follow the steps and confirm after completing them."), this);
|
||||
label->setFont(font);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
connect(openBtn_, &QPushButton::clicked, [session, authType]() {
|
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/%4/"
|
||||
"fallback/web?session=%3")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(session)
|
||||
.arg(authType);
|
||||
connect(openBtn_, &QPushButton::clicked, [session, authType]() {
|
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/%4/"
|
||||
"fallback/web?session=%3")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(session)
|
||||
.arg(authType);
|
||||
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit confirmation();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit cancel();
|
||||
emit close();
|
||||
});
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit confirmation();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit cancel();
|
||||
emit close();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,18 @@ namespace dialogs {
|
|||
|
||||
class FallbackAuth : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FallbackAuth(const QString &authType, const QString &session, QWidget *parent = nullptr);
|
||||
FallbackAuth(const QString &authType, const QString &session, QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void confirmation();
|
||||
void cancel();
|
||||
void confirmation();
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
QPushButton *openBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *openBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -19,84 +19,83 @@ ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent)
|
|||
: QWidget{parent}
|
||||
, originalImage_{image}
|
||||
{
|
||||
setMouseTracking(true);
|
||||
setParent(nullptr);
|
||||
setMouseTracking(true);
|
||||
setParent(nullptr);
|
||||
|
||||
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
|
||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setWindowState(Qt::WindowFullScreen);
|
||||
close_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setWindowState(Qt::WindowFullScreen);
|
||||
close_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||
|
||||
connect(close_shortcut_, &QShortcut::activated, this, &ImageOverlay::closing);
|
||||
connect(this, &ImageOverlay::closing, this, &ImageOverlay::close);
|
||||
connect(close_shortcut_, &QShortcut::activated, this, &ImageOverlay::closing);
|
||||
connect(this, &ImageOverlay::closing, this, &ImageOverlay::close);
|
||||
|
||||
raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void
|
||||
ImageOverlay::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
// Full screen overlay.
|
||||
painter.fillRect(QRect(0, 0, width(), height()), QColor(55, 55, 55, 170));
|
||||
// Full screen overlay.
|
||||
painter.fillRect(QRect(0, 0, width(), height()), QColor(55, 55, 55, 170));
|
||||
|
||||
// Left and Right margins
|
||||
int outer_margin = width() * 0.12;
|
||||
int buttonSize = 36;
|
||||
int margin = outer_margin * 0.1;
|
||||
// Left and Right margins
|
||||
int outer_margin = width() * 0.12;
|
||||
int buttonSize = 36;
|
||||
int margin = outer_margin * 0.1;
|
||||
|
||||
int max_width = width() - 2 * outer_margin;
|
||||
int max_height = height();
|
||||
int max_width = width() - 2 * outer_margin;
|
||||
int max_height = height();
|
||||
|
||||
image_ = utils::scaleDown(max_width, max_height, originalImage_);
|
||||
image_ = utils::scaleDown(max_width, max_height, originalImage_);
|
||||
|
||||
int diff_x = max_width - image_.width();
|
||||
int diff_y = max_height - image_.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(width() - margin - buttonSize, margin, buttonSize, buttonSize);
|
||||
save_button_ =
|
||||
QRect(width() - (2 * margin) - (2 * buttonSize), margin, buttonSize, buttonSize);
|
||||
content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height());
|
||||
close_button_ = QRect(width() - margin - buttonSize, margin, buttonSize, buttonSize);
|
||||
save_button_ = QRect(width() - (2 * margin) - (2 * buttonSize), margin, buttonSize, buttonSize);
|
||||
|
||||
// Draw main content_.
|
||||
painter.drawPixmap(content_, image_);
|
||||
// Draw main content_.
|
||||
painter.drawPixmap(content_, image_);
|
||||
|
||||
// Draw top right corner X.
|
||||
QPen pen;
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
pen.setWidthF(5);
|
||||
pen.setColor("gray");
|
||||
// Draw top right corner X.
|
||||
QPen pen;
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
pen.setWidthF(5);
|
||||
pen.setColor("gray");
|
||||
|
||||
auto center = close_button_.center();
|
||||
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));
|
||||
painter.setPen(pen);
|
||||
painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15));
|
||||
painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15));
|
||||
|
||||
// Draw download button
|
||||
center = save_button_.center();
|
||||
painter.drawLine(center - QPointF(0, 15), center + QPointF(0, 15));
|
||||
painter.drawLine(center - QPointF(15, 0), center + QPointF(0, 15));
|
||||
painter.drawLine(center + QPointF(0, 15), center + QPointF(15, 0));
|
||||
// Draw download button
|
||||
center = save_button_.center();
|
||||
painter.drawLine(center - QPointF(0, 15), center + QPointF(0, 15));
|
||||
painter.drawLine(center - QPointF(15, 0), center + QPointF(0, 15));
|
||||
painter.drawLine(center + QPointF(0, 15), center + QPointF(15, 0));
|
||||
}
|
||||
|
||||
void
|
||||
ImageOverlay::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (close_button_.contains(event->pos()))
|
||||
emit closing();
|
||||
else if (save_button_.contains(event->pos()))
|
||||
emit saving();
|
||||
else if (!content_.contains(event->pos()))
|
||||
emit closing();
|
||||
if (close_button_.contains(event->pos()))
|
||||
emit closing();
|
||||
else if (save_button_.contains(event->pos()))
|
||||
emit saving();
|
||||
else if (!content_.contains(event->pos()))
|
||||
emit closing();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,25 +14,25 @@ namespace dialogs {
|
|||
|
||||
class ImageOverlay : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageOverlay(QPixmap image, QWidget *parent = nullptr);
|
||||
ImageOverlay(QPixmap image, QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
signals:
|
||||
void closing();
|
||||
void saving();
|
||||
void closing();
|
||||
void saving();
|
||||
|
||||
private:
|
||||
QPixmap originalImage_;
|
||||
QPixmap image_;
|
||||
QPixmap originalImage_;
|
||||
QPixmap image_;
|
||||
|
||||
QRect content_;
|
||||
QRect close_button_;
|
||||
QRect save_button_;
|
||||
QShortcut *close_shortcut_;
|
||||
QRect content_;
|
||||
QRect close_button_;
|
||||
QRect save_button_;
|
||||
QShortcut *close_shortcut_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -16,58 +16,58 @@ using namespace dialogs;
|
|||
JoinRoom::JoinRoom(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(15);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(15);
|
||||
|
||||
confirmBtn_ = new QPushButton(tr("Join"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Join"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
roomInput_ = new TextField(this);
|
||||
roomInput_->setLabel(tr("Room ID or alias"));
|
||||
roomInput_ = new TextField(this);
|
||||
roomInput_->setLabel(tr("Room ID or alias"));
|
||||
|
||||
layout->addWidget(roomInput_);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addStretch(1);
|
||||
layout->addWidget(roomInput_);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addStretch(1);
|
||||
|
||||
connect(roomInput_, &QLineEdit::returnPressed, this, &JoinRoom::handleInput);
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, &JoinRoom::handleInput);
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &JoinRoom::close);
|
||||
connect(roomInput_, &QLineEdit::returnPressed, this, &JoinRoom::handleInput);
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, &JoinRoom::handleInput);
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &JoinRoom::close);
|
||||
}
|
||||
|
||||
void
|
||||
JoinRoom::handleInput()
|
||||
{
|
||||
if (roomInput_->text().isEmpty())
|
||||
return;
|
||||
if (roomInput_->text().isEmpty())
|
||||
return;
|
||||
|
||||
// TODO: input validation with error messages.
|
||||
emit joinRoom(roomInput_->text());
|
||||
roomInput_->clear();
|
||||
// TODO: input validation with error messages.
|
||||
emit joinRoom(roomInput_->text());
|
||||
roomInput_->clear();
|
||||
|
||||
emit close();
|
||||
emit close();
|
||||
}
|
||||
|
||||
void
|
||||
JoinRoom::showEvent(QShowEvent *event)
|
||||
{
|
||||
roomInput_->setFocus();
|
||||
roomInput_->setFocus();
|
||||
|
||||
QFrame::showEvent(event);
|
||||
QFrame::showEvent(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,24 @@ namespace dialogs {
|
|||
|
||||
class JoinRoom : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
JoinRoom(QWidget *parent = nullptr);
|
||||
JoinRoom(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void joinRoom(const QString &room);
|
||||
void joinRoom(const QString &room);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void handleInput();
|
||||
void handleInput();
|
||||
|
||||
private:
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
|
||||
TextField *roomInput_;
|
||||
TextField *roomInput_;
|
||||
};
|
||||
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -15,39 +15,39 @@ using namespace dialogs;
|
|||
LeaveRoom::LeaveRoom(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(0);
|
||||
buttonLayout->setMargin(0);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(0);
|
||||
buttonLayout->setMargin(0);
|
||||
|
||||
confirmBtn_ = new QPushButton("Leave", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
cancelBtn_->setDefault(true);
|
||||
confirmBtn_ = new QPushButton("Leave", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
cancelBtn_->setDefault(true);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->setSpacing(15);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->setSpacing(15);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
auto label = new QLabel(tr("Are you sure you want to leave?"), this);
|
||||
auto label = new QLabel(tr("Are you sure you want to leave?"), this);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit leaving();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &LeaveRoom::close);
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit leaving();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &LeaveRoom::close);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@ namespace dialogs {
|
|||
|
||||
class LeaveRoom : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LeaveRoom(QWidget *parent = nullptr);
|
||||
explicit LeaveRoom(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void leaving();
|
||||
void leaving();
|
||||
|
||||
private:
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -15,40 +15,40 @@ using namespace dialogs;
|
|||
Logout::Logout(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(0);
|
||||
buttonLayout->setMargin(0);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(0);
|
||||
buttonLayout->setMargin(0);
|
||||
|
||||
confirmBtn_ = new QPushButton("Logout", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
cancelBtn_->setDefault(true);
|
||||
confirmBtn_ = new QPushButton("Logout", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
cancelBtn_->setDefault(true);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->setSpacing(15);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->setSpacing(15);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
auto label = new QLabel(tr("Logout. Are you sure?"), this);
|
||||
auto label = new QLabel(tr("Logout. Are you sure?"), this);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addStretch(1);
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addStretch(1);
|
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit loggingOut();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &Logout::close);
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit loggingOut();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, &Logout::close);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@ namespace dialogs {
|
|||
|
||||
class Logout : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Logout(QWidget *parent = nullptr);
|
||||
explicit Logout(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void loggingOut();
|
||||
void loggingOut();
|
||||
|
||||
private:
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -29,188 +29,185 @@ PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent)
|
|||
, upload_{tr("Upload"), this}
|
||||
, cancel_{tr("Cancel"), this}
|
||||
{
|
||||
auto hlayout = new QHBoxLayout;
|
||||
hlayout->addStretch(1);
|
||||
hlayout->addWidget(&cancel_);
|
||||
hlayout->addWidget(&upload_);
|
||||
hlayout->setMargin(0);
|
||||
auto hlayout = new QHBoxLayout;
|
||||
hlayout->addStretch(1);
|
||||
hlayout->addWidget(&cancel_);
|
||||
hlayout->addWidget(&upload_);
|
||||
hlayout->setMargin(0);
|
||||
|
||||
auto vlayout = new QVBoxLayout{this};
|
||||
vlayout->addWidget(&titleLabel_);
|
||||
vlayout->addWidget(&infoLabel_);
|
||||
vlayout->addWidget(&fileName_);
|
||||
vlayout->addLayout(hlayout);
|
||||
vlayout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
vlayout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto vlayout = new QVBoxLayout{this};
|
||||
vlayout->addWidget(&titleLabel_);
|
||||
vlayout->addWidget(&infoLabel_);
|
||||
vlayout->addWidget(&fileName_);
|
||||
vlayout->addLayout(hlayout);
|
||||
vlayout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
vlayout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
upload_.setDefault(true);
|
||||
connect(&upload_, &QPushButton::clicked, [this]() {
|
||||
emit confirmUpload(data_, mediaType_, fileName_.text());
|
||||
close();
|
||||
});
|
||||
upload_.setDefault(true);
|
||||
connect(&upload_, &QPushButton::clicked, [this]() {
|
||||
emit confirmUpload(data_, mediaType_, fileName_.text());
|
||||
close();
|
||||
});
|
||||
|
||||
connect(&fileName_, &QLineEdit::returnPressed, this, [this]() {
|
||||
emit confirmUpload(data_, mediaType_, fileName_.text());
|
||||
close();
|
||||
});
|
||||
connect(&fileName_, &QLineEdit::returnPressed, this, [this]() {
|
||||
emit confirmUpload(data_, mediaType_, fileName_.text());
|
||||
close();
|
||||
});
|
||||
|
||||
connect(&cancel_, &QPushButton::clicked, this, [this]() {
|
||||
emit aborted();
|
||||
close();
|
||||
});
|
||||
connect(&cancel_, &QPushButton::clicked, this, [this]() {
|
||||
emit aborted();
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::init()
|
||||
{
|
||||
QSize winsize;
|
||||
QPoint center;
|
||||
QSize winsize;
|
||||
QPoint center;
|
||||
|
||||
auto window = MainWindow::instance();
|
||||
if (window) {
|
||||
winsize = window->frameGeometry().size();
|
||||
center = window->frameGeometry().center();
|
||||
} else {
|
||||
nhlog::ui()->warn("unable to retrieve MainWindow's size");
|
||||
}
|
||||
auto window = MainWindow::instance();
|
||||
if (window) {
|
||||
winsize = window->frameGeometry().size();
|
||||
center = window->frameGeometry().center();
|
||||
} else {
|
||||
nhlog::ui()->warn("unable to retrieve MainWindow's size");
|
||||
}
|
||||
|
||||
fileName_.setText(QFileInfo{filePath_}.fileName());
|
||||
fileName_.setText(QFileInfo{filePath_}.fileName());
|
||||
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
|
||||
titleLabel_.setFont(font);
|
||||
titleLabel_.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
titleLabel_.setAlignment(Qt::AlignCenter);
|
||||
infoLabel_.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
fileName_.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
fileName_.setAlignment(Qt::AlignCenter);
|
||||
upload_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
cancel_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
titleLabel_.setFont(font);
|
||||
titleLabel_.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
titleLabel_.setAlignment(Qt::AlignCenter);
|
||||
infoLabel_.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
fileName_.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
fileName_.setAlignment(Qt::AlignCenter);
|
||||
upload_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
cancel_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
if (isImage_) {
|
||||
infoLabel_.setAlignment(Qt::AlignCenter);
|
||||
if (isImage_) {
|
||||
infoLabel_.setAlignment(Qt::AlignCenter);
|
||||
|
||||
const auto maxWidth = winsize.width() * 0.8;
|
||||
const auto maxHeight = winsize.height() * 0.8;
|
||||
const auto maxWidth = winsize.width() * 0.8;
|
||||
const auto maxHeight = winsize.height() * 0.8;
|
||||
|
||||
// Scale image preview to fit into the application window.
|
||||
infoLabel_.setPixmap(utils::scaleDown(maxWidth, maxHeight, image_));
|
||||
move(center.x() - (width() * 0.5), center.y() - (height() * 0.5));
|
||||
} else {
|
||||
infoLabel_.setAlignment(Qt::AlignLeft);
|
||||
}
|
||||
infoLabel_.setScaledContents(false);
|
||||
// Scale image preview to fit into the application window.
|
||||
infoLabel_.setPixmap(utils::scaleDown(maxWidth, maxHeight, image_));
|
||||
move(center.x() - (width() * 0.5), center.y() - (height() * 0.5));
|
||||
} else {
|
||||
infoLabel_.setAlignment(Qt::AlignLeft);
|
||||
}
|
||||
infoLabel_.setScaledContents(false);
|
||||
|
||||
show();
|
||||
show();
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64_t upload_size)
|
||||
{
|
||||
if (mediaType_.split('/')[0] == "image") {
|
||||
if (!image_.loadFromData(data_)) {
|
||||
titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type));
|
||||
} else {
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg(mediaType_));
|
||||
}
|
||||
isImage_ = true;
|
||||
if (mediaType_.split('/')[0] == "image") {
|
||||
if (!image_.loadFromData(data_)) {
|
||||
titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type));
|
||||
} else {
|
||||
auto const info = QString{tr("Media type: %1\n"
|
||||
"Media size: %2\n")}
|
||||
.arg(mime)
|
||||
.arg(utils::humanReadableFileSize(upload_size));
|
||||
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg("file"));
|
||||
infoLabel_.setText(info);
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg(mediaType_));
|
||||
}
|
||||
isImage_ = true;
|
||||
} else {
|
||||
auto const info = QString{tr("Media type: %1\n"
|
||||
"Media size: %2\n")}
|
||||
.arg(mime)
|
||||
.arg(utils::humanReadableFileSize(upload_size));
|
||||
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg("file"));
|
||||
infoLabel_.setText(info);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::setPreview(const QImage &src, const QString &mime)
|
||||
{
|
||||
nhlog::ui()->info("Pasting image with size: {}x{}, format: {}",
|
||||
src.height(),
|
||||
src.width(),
|
||||
mime.toStdString());
|
||||
nhlog::ui()->info(
|
||||
"Pasting image with size: {}x{}, format: {}", src.height(), src.width(), mime.toStdString());
|
||||
|
||||
auto const &split = mime.split('/');
|
||||
auto const &type = split[1];
|
||||
|
||||
QBuffer buffer(&data_);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
if (src.save(&buffer, type.toStdString().c_str()))
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg("image"));
|
||||
else
|
||||
titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type));
|
||||
|
||||
mediaType_ = mime;
|
||||
filePath_ = "clipboard." + type;
|
||||
image_.convertFromImage(src);
|
||||
isImage_ = true;
|
||||
auto const &split = mime.split('/');
|
||||
auto const &type = split[1];
|
||||
|
||||
QBuffer buffer(&data_);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
if (src.save(&buffer, type.toStdString().c_str()))
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg("image"));
|
||||
init();
|
||||
else
|
||||
titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type));
|
||||
|
||||
mediaType_ = mime;
|
||||
filePath_ = "clipboard." + type;
|
||||
image_.convertFromImage(src);
|
||||
isImage_ = true;
|
||||
|
||||
titleLabel_.setText(QString{tr(DEFAULT)}.arg("image"));
|
||||
init();
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime)
|
||||
{
|
||||
auto const &split = mime.split('/');
|
||||
auto const &type = split[1];
|
||||
auto const &split = mime.split('/');
|
||||
auto const &type = split[1];
|
||||
|
||||
data_ = data;
|
||||
mediaType_ = mime;
|
||||
filePath_ = "clipboard." + type;
|
||||
isImage_ = false;
|
||||
data_ = data;
|
||||
mediaType_ = mime;
|
||||
filePath_ = "clipboard." + type;
|
||||
isImage_ = false;
|
||||
|
||||
setLabels(type, mime, data_.size());
|
||||
init();
|
||||
setLabels(type, mime, data_.size());
|
||||
init();
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::setPreview(const QString &path)
|
||||
{
|
||||
QFile file{path};
|
||||
QFile file{path};
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
nhlog::ui()->warn("Failed to open file ({}): {}",
|
||||
path.toStdString(),
|
||||
file.errorString().toStdString());
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
nhlog::ui()->warn(
|
||||
"Failed to open file ({}): {}", path.toStdString(), file.errorString().toStdString());
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
QMimeDatabase db;
|
||||
auto mime = db.mimeTypeForFileNameAndData(path, &file);
|
||||
QMimeDatabase db;
|
||||
auto mime = db.mimeTypeForFileNameAndData(path, &file);
|
||||
|
||||
if ((data_ = file.readAll()).isEmpty()) {
|
||||
nhlog::ui()->warn("Failed to read media: {}", file.errorString().toStdString());
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if ((data_ = file.readAll()).isEmpty()) {
|
||||
nhlog::ui()->warn("Failed to read media: {}", file.errorString().toStdString());
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
auto const &split = mime.name().split('/');
|
||||
auto const &split = mime.name().split('/');
|
||||
|
||||
mediaType_ = mime.name();
|
||||
filePath_ = file.fileName();
|
||||
isImage_ = false;
|
||||
mediaType_ = mime.name();
|
||||
filePath_ = file.fileName();
|
||||
isImage_ = false;
|
||||
|
||||
setLabels(split[1], mime.name(), data_.size());
|
||||
init();
|
||||
setLabels(split[1], mime.name(), data_.size());
|
||||
init();
|
||||
}
|
||||
|
||||
void
|
||||
PreviewUploadOverlay::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->matches(QKeySequence::Cancel)) {
|
||||
emit aborted();
|
||||
close();
|
||||
} else {
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
if (event->matches(QKeySequence::Cancel)) {
|
||||
emit aborted();
|
||||
close();
|
||||
} else {
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,35 +18,35 @@ namespace dialogs {
|
|||
|
||||
class PreviewUploadOverlay : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
PreviewUploadOverlay(QWidget *parent = nullptr);
|
||||
PreviewUploadOverlay(QWidget *parent = nullptr);
|
||||
|
||||
void setPreview(const QImage &src, const QString &mime);
|
||||
void setPreview(const QByteArray data, const QString &mime);
|
||||
void setPreview(const QString &path);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void setPreview(const QImage &src, const QString &mime);
|
||||
void setPreview(const QByteArray data, const QString &mime);
|
||||
void setPreview(const QString &path);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
signals:
|
||||
void confirmUpload(const QByteArray data, const QString &media, const QString &filename);
|
||||
void aborted();
|
||||
void confirmUpload(const QByteArray data, const QString &media, const QString &filename);
|
||||
void aborted();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void setLabels(const QString &type, const QString &mime, uint64_t upload_size);
|
||||
void init();
|
||||
void setLabels(const QString &type, const QString &mime, uint64_t upload_size);
|
||||
|
||||
bool isImage_;
|
||||
QPixmap image_;
|
||||
bool isImage_;
|
||||
QPixmap image_;
|
||||
|
||||
QByteArray data_;
|
||||
QString filePath_;
|
||||
QString mediaType_;
|
||||
QByteArray data_;
|
||||
QString filePath_;
|
||||
QString mediaType_;
|
||||
|
||||
QLabel titleLabel_;
|
||||
QLabel infoLabel_;
|
||||
QLineEdit fileName_;
|
||||
QLabel titleLabel_;
|
||||
QLabel infoLabel_;
|
||||
QLineEdit fileName_;
|
||||
|
||||
QPushButton upload_;
|
||||
QPushButton cancel_;
|
||||
QPushButton upload_;
|
||||
QPushButton cancel_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
|
|
@ -18,54 +18,54 @@ using namespace dialogs;
|
|||
ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
||||
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(8);
|
||||
buttonLayout->setMargin(0);
|
||||
auto buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->setSpacing(8);
|
||||
buttonLayout->setMargin(0);
|
||||
|
||||
openCaptchaBtn_ = new QPushButton("Open reCAPTCHA", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Confirm"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
openCaptchaBtn_ = new QPushButton("Open reCAPTCHA", this);
|
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
||||
confirmBtn_ = new QPushButton(tr("Confirm"), this);
|
||||
confirmBtn_->setDefault(true);
|
||||
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(openCaptchaBtn_);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(openCaptchaBtn_);
|
||||
buttonLayout->addWidget(cancelBtn_);
|
||||
buttonLayout->addWidget(confirmBtn_);
|
||||
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
QFont font;
|
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
||||
|
||||
auto label = new QLabel(tr("Solve the reCAPTCHA and press the confirm button"), this);
|
||||
label->setFont(font);
|
||||
auto label = new QLabel(tr("Solve the reCAPTCHA and press the confirm button"), this);
|
||||
label->setFont(font);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addWidget(label);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
connect(openCaptchaBtn_, &QPushButton::clicked, [session]() {
|
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/"
|
||||
"fallback/web?session=%3")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(session);
|
||||
connect(openCaptchaBtn_, &QPushButton::clicked, [session]() {
|
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/"
|
||||
"fallback/web?session=%3")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(session);
|
||||
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit confirmation();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit cancel();
|
||||
emit close();
|
||||
});
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit confirmation();
|
||||
emit close();
|
||||
});
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
||||
emit cancel();
|
||||
emit close();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@ namespace dialogs {
|
|||
|
||||
class ReCaptcha : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ReCaptcha(const QString &session, QWidget *parent = nullptr);
|
||||
ReCaptcha(const QString &session, QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void confirmation();
|
||||
void cancel();
|
||||
void confirmation();
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
QPushButton *openCaptchaBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
QPushButton *openCaptchaBtn_;
|
||||
QPushButton *confirmBtn_;
|
||||
QPushButton *cancelBtn_;
|
||||
};
|
||||
} // dialogs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue