Skip to content

Commit

Permalink
修复反复改变大小,时尚模式图标变模糊的bug;优化时尚模式sizehint
Browse files Browse the repository at this point in the history
  • Loading branch information
sonichy committed Apr 21, 2020
1 parent a8cc81a commit 8ad630f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions weatherplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]\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: [email protected]\nSource: https://github.com/sonichy/WEATHER_DDE_DOCK\nAPI: https://openweathermap.org/forecast5");
aboutMB.setIconPixmap(QPixmap(":/icon/Default/01d.png"));
aboutMB.exec();
}
Expand All @@ -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());
Expand All @@ -213,14 +213,15 @@ 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));
}

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");
Expand Down Expand Up @@ -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){
Expand Down
12 changes: 7 additions & 5 deletions weatherwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dock::Position>();
if (position == Dock::Top || position == Dock::Bottom)
size = QSize(height(), height());
else
size = QSize(width(), width());
}
return size;
}
Expand All @@ -53,13 +57,11 @@ void WeatherWidget::paintEvent(QPaintEvent *e)
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
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);
}
}

0 comments on commit 8ad630f

Please sign in to comment.