From 8ad630fca108df2362853aa3e19607af50af1751 Mon Sep 17 00:00:00 2001 From: sonichy Date: Tue, 21 Apr 2020 17:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=8D=E5=A4=8D=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E5=A4=A7=E5=B0=8F=EF=BC=8C=E6=97=B6=E5=B0=9A=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=9B=BE=E6=A0=87=E5=8F=98=E6=A8=A1=E7=B3=8A=E7=9A=84?= =?UTF-8?q?bug=EF=BC=9B=E4=BC=98=E5=8C=96=E6=97=B6=E5=B0=9A=E6=A8=A1?= =?UTF-8?q?=E5=BC=8Fsizehint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weatherplugin.cpp | 9 ++++++--- weatherwidget.cpp | 12 +++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/weatherplugin.cpp b/weatherplugin.cpp index 7bc53d2..4a635be 100644 --- a/weatherplugin.cpp +++ b/weatherplugin.cpp @@ -165,7 +165,7 @@ void WeatherPlugin::invokedMenuItem(const QString &itemKey, const QString &menuI void WeatherPlugin::MBAbout() { - QMessageBox aboutMB(QMessageBox::NoIcon, "HTYWeather 5.7", "About\n\nDeepin Linux Dock Weather Plugin.\nAuthor: 黄颖\nE-mail: sonichy@163.com\nSource: https://github.com/sonichy/WEATHER_DDE_DOCK\nAPI: https://openweathermap.org/forecast5"); + QMessageBox aboutMB(QMessageBox::NoIcon, "HTYWeather 5.8", "About\n\nDeepin Linux Dock Weather Plugin.\nAuthor: 海天鹰\nE-mail: sonichy@163.com\nSource: https://github.com/sonichy/WEATHER_DDE_DOCK\nAPI: https://openweathermap.org/forecast5"); aboutMB.setIconPixmap(QPixmap(":/icon/Default/01d.png")); aboutMB.exec(); } @@ -189,7 +189,7 @@ void WeatherPlugin::showMap() QDateTime currentDateTime = QDateTime::currentDateTime(); QString log = currentDateTime.toString("yyyy/MM/dd HH:mm:ss") + " : " + surl; - QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first() + "/HTYWeather.log"; + QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/HTYWeather.log"; QFile file(path); if (file.open(QFile::WriteOnly | QFile::Append)) { file.write(log.toUtf8()); @@ -213,7 +213,7 @@ void WeatherPlugin::showMap() void WeatherPlugin::showLog() { - QString surl = "file://" + QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first() + "/HTYWeather.log"; + QString surl = "file://" + QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/HTYWeather.log"; QDesktopServices::openUrl(QUrl(surl)); } @@ -221,6 +221,7 @@ void WeatherPlugin::set() { QDialog *dialog = new QDialog; dialog->setWindowTitle("Set"); + dialog->setFixedSize(350, 200); QVBoxLayout *vbox = new QVBoxLayout; QHBoxLayout *hbox = new QHBoxLayout; QLabel *label = new QLabel("City"); @@ -296,8 +297,10 @@ void WeatherPlugin::set() connect(pushButton_confirm, SIGNAL(clicked()), dialog, SLOT(accept())); connect(pushButton_cancel, SIGNAL(clicked()), dialog, SLOT(reject())); hbox = new QHBoxLayout; + hbox->addStretch(); hbox->addWidget(pushButton_confirm); hbox->addWidget(pushButton_cancel); + hbox->addStretch(); vbox->addLayout(hbox); dialog->setLayout(vbox); if(dialog->exec() == QDialog::Accepted){ diff --git a/weatherwidget.cpp b/weatherwidget.cpp index c09c126..556986a 100644 --- a/weatherwidget.cpp +++ b/weatherwidget.cpp @@ -37,7 +37,11 @@ QSize WeatherWidget::sizeHint() const size = FM.boundingRect(temp).size() + QSize(10,FM.boundingRect(temp).height()); } }else{ - size = QPixmap(":icon/na.png").size(); + const Dock::Position position = qApp->property(PROP_POSITION).value(); + if (position == Dock::Top || position == Dock::Bottom) + size = QSize(height(), height()); + else + size = QSize(width(), width()); } return size; } @@ -53,13 +57,11 @@ void WeatherWidget::paintEvent(QPaintEvent *e) const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value(); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setRenderHint(QPainter::SmoothPixmapTransform, true); if (displayMode == Dock::Efficient) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, sw + "\n" + temp); } else { - int w = qMin(width(), height()); - pixmap = pixmap.scaled(w*0.8, w*0.8, Qt::KeepAspectRatio, Qt::SmoothTransformation); - painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap); + QPixmap pixmap1 = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + painter.drawPixmap(rect().center() - pixmap1.rect().center(), pixmap1); } } \ No newline at end of file