diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a7ee1523..e0cbe534 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -283,6 +283,9 @@ MainWindow::MainWindow(QWidget *parent) ui->lineEdit_remote->setText(currentRemoteName()); }); + // 右上のアイコンがクリックされたとき、ConfigUserダイアログを表示 + connect(ui->widget_avatar_icon, &SimpleImageWidget::clicked, this, &MainWindow::on_action_configure_user_triggered); + connect(new QShortcut(QKeySequence("Ctrl+T"), this), &QShortcut::activated, this, &MainWindow::test); // @@ -5633,8 +5636,6 @@ void MainWindow::on_action_configure_user_triggered() execConfigUserDialog(global_user, local_user, enable_local_user, currentRepositoryName()); } - - void MainWindow::showLogWindow(bool show) { ui->dockWidget_log->setVisible(show); diff --git a/src/SimpleImageWidget.cpp b/src/SimpleImageWidget.cpp index fad56d82..41d073c4 100644 --- a/src/SimpleImageWidget.cpp +++ b/src/SimpleImageWidget.cpp @@ -1,21 +1,31 @@ #include "SimpleImageWidget.h" - +#include +#include #include SimpleImageWidget::SimpleImageWidget(QWidget *parent) : QWidget{parent} { - } +/** + * @brief 画像を設定 + * @param image + */ void SimpleImageWidget::setImage(const QImage &image) { image_ = image; update(); } +/** + * @brief SimpleImageWidget::paintEvent + * @param event + */ void SimpleImageWidget::paintEvent(QPaintEvent *event) { + // ウィンドウに内接するように画像を描画 + int dw = width(); int dh = height(); if (dw < 1 || dh < 1) return; @@ -37,3 +47,13 @@ void SimpleImageWidget::paintEvent(QPaintEvent *event) pr.drawImage(QRect(x, y, dw, dh), image_, QRect(0, 0, sw, sh)); } +void SimpleImageWidget::mouseReleaseEvent(QMouseEvent *event) +{ + // マウス左ボタンが離されたときウィンドウ座標内ならクリックされたことにする + if (event->button() == Qt::LeftButton) { + if (rect().contains(event->pos())) { + emit clicked(); + } + } +} + diff --git a/src/SimpleImageWidget.h b/src/SimpleImageWidget.h index 6b37b932..f0dc801e 100644 --- a/src/SimpleImageWidget.h +++ b/src/SimpleImageWidget.h @@ -5,13 +5,16 @@ class SimpleImageWidget : public QWidget { Q_OBJECT -private: - QImage image_; -protected: - void paintEvent(QPaintEvent *event); public: explicit SimpleImageWidget(QWidget *parent = nullptr); void setImage(QImage const &image); +protected: + void paintEvent(QPaintEvent *event); + void mouseReleaseEvent(QMouseEvent *event); +private: + QImage image_; +signals: + void clicked(); }; #endif // SIMPLEIMAGEWIDGET_H