| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "imginfodialog.h" |
| 22 |
#include "controller/signalmanager.h" |
| 23 |
#include "utils/imageutils.h" |
| 24 |
#include "imageengineapi.h" |
| 25 |
#include "utils/unionimage.h" |
| 26 |
#include "widgets/formlabel.h" |
| 27 |
|
| 28 |
#include "dfmdarrowlineexpand.h" |
| 29 |
|
| 30 |
#include <QFormLayout> |
| 31 |
#include <QLocale> |
| 32 |
#include <QApplication> |
| 33 |
#include <QScrollBar> |
| 34 |
|
| 35 |
#include <DTitlebar> |
| 36 |
#include <DApplicationHelper> |
| 37 |
#include <DFontSizeManager> |
| 38 |
|
| 39 |
namespace { |
| 40 |
|
| 41 |
struct MetaData { |
| 42 |
QString key; |
| 43 |
const char *name; |
| 44 |
}; |
| 45 |
|
| 46 |
static MetaData MetaDataBasics[] = { |
| 47 |
{"FileName", QT_TRANSLATE_NOOP("MetadataName", "Photo name")}, |
| 48 |
|
| 49 |
{"DateTimeOriginal", QT_TRANSLATE_NOOP("MetadataName", "Date captured")}, |
| 50 |
{"DateTimeDigitized", QT_TRANSLATE_NOOP("MetadataName", "Date modified")}, |
| 51 |
{"FileFormat", QT_TRANSLATE_NOOP("MetadataName", "Type")}, |
| 52 |
{"Dimensions", QT_TRANSLATE_NOOP("MetadataName", "Dimensions")}, |
| 53 |
{"FileSize", QT_TRANSLATE_NOOP("MetadataName", "File size")}, |
| 54 |
|
| 55 |
// {"MaxApertureValue", QT_TRANSLATE_NOOP("MetadataName", "Max aperture")}, |
| 56 |
// {"FocalLength", QT_TRANSLATE_NOOP("MetadataName", "Focal length")}, |
| 57 |
{"", ""} |
| 58 |
}; |
| 59 |
|
| 60 |
static MetaData MetaDataDetails[] = { |
| 61 |
{"ColorSpace", QT_TRANSLATE_NOOP("MetadataName", "Colorspace")}, |
| 62 |
{"ExposureMode", QT_TRANSLATE_NOOP("MetadataName", "Exposure mode")}, |
| 63 |
{"ExposureProgram", QT_TRANSLATE_NOOP("MetadataName", "Exposure program")}, |
| 64 |
{"ExposureTime", QT_TRANSLATE_NOOP("MetadataName", "Exposure time")}, |
| 65 |
{"Flash", QT_TRANSLATE_NOOP("MetadataName", "Flash")}, |
| 66 |
{"ApertureValue", QT_TRANSLATE_NOOP("MetadataName", "Aperture")}, |
| 67 |
{"FocalLength", QT_TRANSLATE_NOOP("MetadataName", "Focal length")}, |
| 68 |
{"ISOSpeedRatings", QT_TRANSLATE_NOOP("MetadataName", "ISO")}, |
| 69 |
{"MaxApertureValue", QT_TRANSLATE_NOOP("MetadataName", "Max aperture")}, |
| 70 |
{"MeteringMode", QT_TRANSLATE_NOOP("MetadataName", "Metering mode")}, |
| 71 |
{"WhiteBalance", QT_TRANSLATE_NOOP("MetadataName", "White balance")}, |
| 72 |
{"FlashExposureComp", QT_TRANSLATE_NOOP("MetadataName", "Flash compensation")}, |
| 73 |
{"Model", QT_TRANSLATE_NOOP("MetadataName", "Camera model")}, |
| 74 |
{"LensType", QT_TRANSLATE_NOOP("MetadataName", "Lens model")}, |
| 75 |
{"", ""} |
| 76 |
}; |
| 77 |
|
| 78 |
} // namespace |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
ImgInfoDialog::ImgInfoDialog(const QString &path, QWidget *parent) |
| 83 |
: DDialog(parent), m_title_maxwidth(0), m_maxFieldWidth(0), |
| 84 |
m_isBaseInfo(false), m_isDetailsInfo(false), m_exif_base(nullptr), |
| 85 |
m_exif_details(nullptr), m_exifLayout_base(nullptr), m_exifLayout_details(nullptr), |
| 86 |
m_mainLayout(nullptr), m_scrollArea(nullptr) |
| 87 |
{ |
| 88 |
//LMH0424默认字体大小 |
| 89 |
QFont font; |
| 90 |
m_currentFontSize = DFontSizeManager::instance()->fontPixelSize(font); |
| 91 |
QLocale locale; |
| 92 |
if (locale.language() == QLocale::Chinese) //语言为中文 |
| 93 |
m_title_maxwidth = 60; |
| 94 |
else |
| 95 |
m_title_maxwidth = 108; |
| 96 |
|
| 97 |
initUI(); |
| 98 |
setImagePath(path); |
| 99 |
} |
| 100 |
|
| 101 |
int ImgInfoDialog::height() |
| 102 |
{ |
| 103 |
return contentHeight() + 10; |
| 104 |
} |
| 105 |
|
| 106 |
void ImgInfoDialog::initUI() |
| 107 |
{ |
| 108 |
// setAutoFillBackground(true); |
| 109 |
setAttribute(Qt::WA_TranslucentBackground, true); |
| 110 |
setFixedWidth(320); |
| 111 |
setMaximumHeight(540); |
| 112 |
setContentLayoutContentsMargins(QMargins(0, 0, 0, 0)); |
| 113 |
|
| 114 |
//title |
| 115 |
DLabel *title = new DLabel(this); |
| 116 |
title->setText(tr("Photo info")); |
| 117 |
title->setGeometry(this->x() + (this->width() - title->width()) / 2, this->y(), 112, 50); |
| 118 |
title->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
| 119 |
DFontSizeManager::instance()->bind(title, DFontSizeManager::T6); |
| 120 |
DPalette pa = DApplicationHelper::instance()->palette(title); |
| 121 |
pa.setBrush(DPalette::Text, pa.color(DPalette::TextTitle)); |
| 122 |
title->setPalette(pa); |
| 123 |
|
| 124 |
setContentsMargins(0, 0, 0, 0); |
| 125 |
|
| 126 |
DWidget *content = new DWidget(); |
| 127 |
addContent(content); |
| 128 |
|
| 129 |
m_exif_base = new QFrame(this); |
| 130 |
m_exif_base->setFixedWidth(280); |
| 131 |
m_exif_details = new QFrame(this); |
| 132 |
m_exif_details->setFixedWidth(280); |
| 133 |
m_exifLayout_base = new QFormLayout(); |
| 134 |
m_exifLayout_base->setVerticalSpacing(7); |
| 135 |
m_exifLayout_base->setHorizontalSpacing(16); |
| 136 |
m_exifLayout_base->setContentsMargins(10, 1, 7, 10); |
| 137 |
m_exifLayout_base->setLabelAlignment(Qt::AlignLeft); |
| 138 |
|
| 139 |
m_exifLayout_details = new QFormLayout(); |
| 140 |
|
| 141 |
m_exifLayout_details->setVerticalSpacing(7); |
| 142 |
m_exifLayout_details->setHorizontalSpacing(16); |
| 143 |
m_exifLayout_details->setContentsMargins(10, 1, 7, 10); |
| 144 |
m_exifLayout_details->setLabelAlignment(Qt::AlignLeft); |
| 145 |
|
| 146 |
m_exif_base->setLayout(m_exifLayout_base); |
| 147 |
m_exif_details->setLayout(m_exifLayout_details); |
| 148 |
|
| 149 |
m_mainLayout = new QVBoxLayout; |
| 150 |
|
| 151 |
m_mainLayout->setContentsMargins(0, 0, 0, 0); |
| 152 |
m_mainLayout->setMargin(0); |
| 153 |
m_mainLayout->setSpacing(0); |
| 154 |
|
| 155 |
m_scrollArea = new DScrollArea(); |
| 156 |
DPalette palette = m_scrollArea->viewport()->palette(); |
| 157 |
palette.setBrush(DPalette::Background, Qt::NoBrush); |
| 158 |
m_scrollArea->viewport()->setPalette(palette); |
| 159 |
m_scrollArea->setFrameShape(QFrame::Shape::NoFrame); |
| 160 |
QFrame *infoframe = new QFrame; |
| 161 |
QVBoxLayout *scrollWidgetLayout = new QVBoxLayout; |
| 162 |
scrollWidgetLayout->setContentsMargins(10, 0, 10, 0); |
| 163 |
scrollWidgetLayout->setSpacing(10); |
| 164 |
infoframe->setLayout(scrollWidgetLayout); |
| 165 |
m_scrollArea->setWidget(infoframe); |
| 166 |
m_scrollArea->setWidgetResizable(true); |
| 167 |
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); |
| 168 |
m_scrollArea->viewport()->installEventFilter(this); |
| 169 |
|
| 170 |
QVBoxLayout *scrolllayout = new QVBoxLayout; |
| 171 |
scrolllayout->addWidget(m_scrollArea); |
| 172 |
m_mainLayout->insertLayout(1, scrolllayout, 1); |
| 173 |
|
| 174 |
content->setLayout(m_mainLayout); |
| 175 |
} |
| 176 |
|
| 177 |
void ImgInfoDialog::setImagePath(const QString &path) |
| 178 |
{ |
| 179 |
m_path = path; |
| 180 |
m_isBaseInfo = false; |
| 181 |
m_isDetailsInfo = false; |
| 182 |
updateInfo(); |
| 183 |
|
| 184 |
QStringList titleList; |
| 185 |
QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(m_scrollArea->widget()->layout()); |
| 186 |
if (nullptr != layout) { |
| 187 |
QLayoutItem *child; |
| 188 |
while ((child = layout->takeAt(0)) != nullptr) { |
| 189 |
layout->removeWidget(child->widget()); |
| 190 |
child->widget()->setParent(nullptr); |
| 191 |
delete child; |
| 192 |
} |
| 193 |
} |
| 194 |
m_expandGroup.clear(); |
| 195 |
|
| 196 |
if (m_isBaseInfo == true && m_isDetailsInfo == true) { |
| 197 |
titleList << tr("Basic info"); |
| 198 |
titleList << tr("Details"); |
| 199 |
m_expandGroup = addExpandWidget(titleList); |
| 200 |
m_expandGroup.at(0)->setContent(m_exif_base); |
| 201 |
m_expandGroup.at(0)->setExpand(true); |
| 202 |
m_expandGroup.at(1)->setContent(m_exif_details); |
| 203 |
m_expandGroup.at(1)->setExpand(true); |
| 204 |
|
| 205 |
} else if (m_isBaseInfo == false && m_isDetailsInfo == true) { |
| 206 |
titleList << tr("Details"); |
| 207 |
m_expandGroup = addExpandWidget(titleList); |
| 208 |
m_expandGroup.at(0)->setContent(m_exif_details); |
| 209 |
m_expandGroup.at(0)->setExpand(true); |
| 210 |
} else if (m_isBaseInfo == true && m_isDetailsInfo == false) { |
| 211 |
titleList << tr("Basic info"); |
| 212 |
m_expandGroup = addExpandWidget(titleList); |
| 213 |
m_expandGroup.at(0)->setContent(m_exif_base); |
| 214 |
m_expandGroup.at(0)->setExpand(true); |
| 215 |
} |
| 216 |
//剔除多余不需要的焦点 |
| 217 |
QList<QWidget *>allwidgetlist = this->findChildren<QWidget *>(); |
| 218 |
for (int i = 0; i < allwidgetlist.size() ; i++) { |
| 219 |
allwidgetlist.at(i)->setFocusPolicy(Qt::NoFocus); |
| 220 |
} |
| 221 |
for (int j = 0; j < m_expandGroup.size(); j++) { |
| 222 |
QList<DIconButton *> expandlist = m_expandGroup.at(j)->findChildren<DIconButton *>(); |
| 223 |
for (int k = 0; k < expandlist.size(); k++) { |
| 224 |
expandlist.at(k)->setFocusPolicy(Qt::TabFocus); |
| 225 |
} |
| 226 |
} |
| 227 |
QWidget *closeButton = this->findChild<QWidget *>("DTitlebarDWindowCloseButton"); |
| 228 |
if (closeButton) { |
| 229 |
closeButton->setFocusPolicy(Qt::TabFocus); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
void ImgInfoDialog::clearLayout(QLayout *layout) |
| 234 |
{ |
| 235 |
QFormLayout *fl = static_cast<QFormLayout *>(layout); |
| 236 |
if (fl) { |
| 237 |
// FIXME fl->rowCount() will always increase |
| 238 |
for (int i = 0; i < fl->rowCount(); i++) { |
| 239 |
QLayoutItem *li = fl->itemAt(i, QFormLayout::LabelRole); |
| 240 |
QLayoutItem *fi = fl->itemAt(i, QFormLayout::FieldRole); |
| 241 |
if (li) { |
| 242 |
if (li->widget()) delete li->widget(); |
| 243 |
fl->removeItem(li); |
| 244 |
} |
| 245 |
if (fi) { |
| 246 |
if (fi->widget()) delete fi->widget(); |
| 247 |
fl->removeItem(fi); |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
const QString ImgInfoDialog::trLabel(const char *str) |
| 254 |
{ |
| 255 |
return qApp->translate("MetadataName", str); |
| 256 |
} |
| 257 |
|
| 258 |
void ImgInfoDialog::updateInfo() |
| 259 |
{ |
| 260 |
auto mds = UnionImage_NameSpace::getAllMetaData(m_path); |
| 261 |
m_maxFieldWidth = width() - m_title_maxwidth - 20 * 2 - 10 * 2; |
| 262 |
updateBaseInfo(mds); |
| 263 |
updateDetailsInfo(mds); |
| 264 |
} |
| 265 |
|
| 266 |
void ImgInfoDialog::updateBaseInfo(const QMap<QString, QString> &infos) |
| 267 |
{ |
| 268 |
using namespace utils::image; |
| 269 |
using namespace utils::base; |
| 270 |
clearLayout(m_exifLayout_base); |
| 271 |
|
| 272 |
for (MetaData *i = MetaDataBasics; ! i->key.isEmpty(); i ++) { |
| 273 |
QString value = infos.value(i->key); |
| 274 |
if (i->key.contains("Dimension")) { |
| 275 |
value = infos.value("Dimension"); |
| 276 |
if (value == "0x0") { |
| 277 |
DBImgInfo st; |
| 278 |
ImageEngineApi::instance()->getImageData(m_path, st); |
| 279 |
value = st.albumSize; |
| 280 |
if (value.isEmpty()) { |
| 281 |
QImage tImg; |
| 282 |
QString errMsg; |
| 283 |
if (!UnionImage_NameSpace::loadStaticImageFromFile(m_path, tImg, errMsg)) { |
| 284 |
qDebug() << errMsg; |
| 285 |
continue; |
| 286 |
} |
| 287 |
value = QString::number(tImg.width()) + "x" + QString::number(tImg.height()); |
| 288 |
} |
| 289 |
} |
| 290 |
} else if (i->key.contains("FileFormat")) { |
| 291 |
QStringList list = value.split("/"); |
| 292 |
if (list.count() > 0) { |
| 293 |
value = list.value(list.count() - 1); |
| 294 |
} |
| 295 |
} else if (i->key == "DateTimeOriginal" || i->key == "DateTimeDigitized") { |
| 296 |
QStringList list = value.split(" "); |
| 297 |
if (2 == list.count()) { |
| 298 |
QStringList listDate = list[0].split("/"); |
| 299 |
if (3 == listDate.count()) { |
| 300 |
value = listDate[0] + "/" + listDate[1] + "/" + listDate[2] + " " + list[1]; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
} |
| 305 |
if (value.isEmpty()) continue; |
| 306 |
|
| 307 |
m_isBaseInfo = true; |
| 308 |
if (!((i->key == "DateTimeOriginal" || i->key == "DateTimeDigitized") && '0' == value.left(1))) { |
| 309 |
SimpleFormField *field = new SimpleFormField; |
| 310 |
field->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 311 |
DFontSizeManager::instance()->bind(field, DFontSizeManager::T8); |
| 312 |
DPalette pa1 = DApplicationHelper::instance()->palette(field); |
| 313 |
pa1.setBrush(DPalette::Text, pa1.color(DPalette::TextTitle)); |
| 314 |
field->setPalette(pa1); |
| 315 |
field->setText(SpliteText(value, field->font(), m_maxFieldWidth)); |
| 316 |
SimpleFormLabel *title = new SimpleFormLabel(trLabel(i->name) + ":"); |
| 317 |
title->setMinimumHeight(field->minimumHeight()); |
| 318 |
title->setFixedWidth(m_title_maxwidth); |
| 319 |
title->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 320 |
//2020/03/13-xiaolong |
| 321 |
DFontSizeManager::instance()->bind(title, DFontSizeManager::T8); |
| 322 |
DPalette pa2 = DApplicationHelper::instance()->palette(title); |
| 323 |
pa2.setBrush(DPalette::Text, pa2.color(DPalette::TextTitle)); |
| 324 |
title->setPalette(pa2); |
| 325 |
QString text1 = i->name; |
| 326 |
title->setText(SpliteText(trLabel(i->name) + ":", title->font(), m_title_maxwidth)); |
| 327 |
QString text = title->text(); |
| 328 |
m_exifLayout_base->addRow(title, field); |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
void ImgInfoDialog::updateDetailsInfo(const QMap<QString, QString> &infos) |
| 334 |
{ |
| 335 |
using namespace utils::image; |
| 336 |
using namespace utils::base; |
| 337 |
clearLayout(m_exifLayout_details); |
| 338 |
for (MetaData *i = MetaDataDetails; ! i->key.isEmpty(); i ++) { |
| 339 |
QString value = infos.value(i->key); |
| 340 |
if (value.isEmpty()) continue; |
| 341 |
m_isDetailsInfo = true; |
| 342 |
SimpleFormField *field = new SimpleFormField; |
| 343 |
field->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 344 |
DFontSizeManager::instance()->bind(field, DFontSizeManager::T8); |
| 345 |
DPalette pa1 = DApplicationHelper::instance()->palette(field); |
| 346 |
pa1.setBrush(DPalette::Text, pa1.color(DPalette::TextTitle)); |
| 347 |
field->setPalette(pa1); |
| 348 |
field->setText(SpliteText(value, field->font(), m_maxFieldWidth)); |
| 349 |
|
| 350 |
SimpleFormLabel *title = new SimpleFormLabel(trLabel(i->name) + ":"); |
| 351 |
title->setMinimumHeight(field->minimumHeight()); |
| 352 |
title->setFixedWidth(m_title_maxwidth); |
| 353 |
title->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 354 |
DFontSizeManager::instance()->bind(title, DFontSizeManager::T8); |
| 355 |
DPalette pa2 = DApplicationHelper::instance()->palette(title); |
| 356 |
pa2.setBrush(DPalette::Text, pa2.color(DPalette::TextTitle)); |
| 357 |
title->setPalette(pa2); |
| 358 |
title->setText(SpliteText(trLabel(i->name) + ":", title->font(), m_title_maxwidth)); |
| 359 |
QString text = title->text(); |
| 360 |
m_exifLayout_details->addRow(title, field); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
QList<DDrawer *> ImgInfoDialog::addExpandWidget(const QStringList &titleList) |
| 365 |
{ |
| 366 |
QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(m_scrollArea->widget()->layout()); |
| 367 |
QList<DDrawer *> group; |
| 368 |
|
| 369 |
for (const QString &title : titleList) { |
| 370 |
DFMDArrowLineExpand *expand = new DFMDArrowLineExpand;//DArrowLineExpand; |
| 371 |
expand->setTitle(title); |
| 372 |
initExpand(layout, expand); |
| 373 |
group.push_back(expand); |
| 374 |
} |
| 375 |
|
| 376 |
return group; |
| 377 |
} |
| 378 |
void ImgInfoDialog::initExpand(QVBoxLayout *layout, DDrawer *expand) |
| 379 |
{ |
| 380 |
expand->setFixedHeight(30); |
| 381 |
QMargins cm = layout->contentsMargins(); |
| 382 |
QRect rc1 = contentsRect(); |
| 383 |
expand->setFixedWidth(rc1.width() - cm.left() - cm.right()); |
| 384 |
// 去掉界面的横线 |
| 385 |
expand->setExpandedSeparatorVisible(false); |
| 386 |
expand->setSeparatorVisible(false); |
| 387 |
layout->addWidget(expand, 0, Qt::AlignTop); |
| 388 |
|
| 389 |
DEnhancedWidget *hanceedWidget = new DEnhancedWidget(expand, this); |
| 390 |
connect(hanceedWidget, &DEnhancedWidget::heightChanged, hanceedWidget, [ = ]() { |
| 391 |
QRect rc = geometry(); |
| 392 |
if (m_expandGroup.count() == 2) { |
| 393 |
rc.setHeight(contentHeight() + 40); |
| 394 |
setGeometry(rc); |
| 395 |
this->setFixedHeight(qMin(615, contentHeight() + 15)); |
| 396 |
} else { |
| 397 |
rc.setHeight(contentHeight() + 40); |
| 398 |
setGeometry(rc); |
| 399 |
this->setFixedHeight(qMin(615, contentHeight() + 25)); |
| 400 |
} |
| 401 |
// if(expand->expand()){ |
| 402 |
// emit dApp->signalM->extensionPanelHeight(qMin(615,contentHeight()+5)); |
| 403 |
// } |
| 404 |
}); |
| 405 |
} |
| 406 |
|
| 407 |
int ImgInfoDialog::contentHeight() const |
| 408 |
{ |
| 409 |
int expandsHeight = 10; |
| 410 |
// bool atleastOneExpand = false; |
| 411 |
// for (const DBaseExpand* expand : m_expandGroup) { |
| 412 |
// expandsHeight += 30 + 15; |
| 413 |
// if (expand->expand()) { |
| 414 |
// expandsHeight += expand->getContent()->height(); |
| 415 |
// atleastOneExpand = true; |
| 416 |
// } |
| 417 |
// } |
| 418 |
// for (const DDrawer *expand : m_expandGroup) { |
| 419 |
// expandsHeight += expand->height(); |
| 420 |
// } |
| 421 |
QList<DDrawer *>::const_iterator expand = m_expandGroup.cbegin(); |
| 422 |
while (expand != m_expandGroup.cend()) { |
| 423 |
expandsHeight += (*expand)->height(); |
| 424 |
++expand; |
| 425 |
} |
| 426 |
return (50 + expandsHeight + contentsMargins().top() + |
| 427 |
contentsMargins().bottom()); |
| 428 |
} |
| 429 |
|
| 430 |
void ImgInfoDialog::keyPressEvent(QKeyEvent *e) |
| 431 |
{ |
| 432 |
if (e->key() == Qt::Key_Escape) { |
| 433 |
this->close(); |
| 434 |
} |
| 435 |
DDialog::keyPressEvent(e); |
| 436 |
} |
| 437 |
//LMH0424检查字体大小随系统改变,从而刷新字体。 |
| 438 |
void ImgInfoDialog::paintEvent(QPaintEvent *event) |
| 439 |
{ |
| 440 |
QFont font; |
| 441 |
int currentSize = DFontSizeManager::instance()->fontPixelSize(font); |
| 442 |
if (currentSize != m_currentFontSize) { |
| 443 |
m_currentFontSize = currentSize; |
| 444 |
updateInfo(); |
| 445 |
} |
| 446 |
DDialog::paintEvent(event); |
| 447 |
} |
| 448 |
|
| 449 |
bool ImgInfoDialog::event(QEvent *event) |
| 450 |
{ |
| 451 |
if (event->type() == QEvent::ActivationChange) { |
| 452 |
if (QApplication::activeWindow() != this) { |
| 453 |
this->close(); |
| 454 |
} |
| 455 |
} |
| 456 |
return QWidget::event(event); |
| 457 |
} |
| 458 |
|
| 459 |
bool ImgInfoDialog::eventFilter(QObject *obj, QEvent *e) |
| 460 |
{ |
| 461 |
if (obj == m_scrollArea->viewport()) { |
| 462 |
QMouseEvent *event = dynamic_cast<QMouseEvent *>(e); |
| 463 |
if (e->type() == QEvent::MouseButtonPress && event) { |
| 464 |
m_mousePress = true; |
| 465 |
m_mouseY = event->pos().y(); |
| 466 |
return true; |
| 467 |
} |
| 468 |
if (e->type() == QEvent::MouseMove && event) { |
| 469 |
int sliderPosition = m_scrollArea->verticalScrollBar()->sliderPosition(); |
| 470 |
if (m_mousePress) { |
| 471 |
if (event->pos().y() < m_mouseY) { |
| 472 |
m_scrollArea->verticalScrollBar()->setSliderPosition(sliderPosition + 1); |
| 473 |
} else if (event->pos().y() > m_mouseY) { |
| 474 |
m_scrollArea->verticalScrollBar()->setSliderPosition(sliderPosition - 1); |
| 475 |
} |
| 476 |
} |
| 477 |
m_mouseY = event->pos().y(); |
| 478 |
return true; |
| 479 |
} |
| 480 |
if (e->type() == QEvent::MouseButtonRelease && event) { |
| 481 |
m_mousePress = false; |
| 482 |
return true; |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
// if (e->type() == QEvent::KeyPress) { |
| 487 |
// QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e); |
| 488 |
// if (keyEvent->key() == Qt::Key_Tab) { |
| 489 |
// if (m_allTabOrder.at(0) == obj) { |
| 490 |
// m_allTabOrder.at(1)->setFocus(); |
| 491 |
// return true; |
| 492 |
// } else if (m_allTabOrder.at(1) == obj) { |
| 493 |
// m_allTabOrder.at(0)->setFocus(); |
| 494 |
// return true; |
| 495 |
// } |
| 496 |
// } |
| 497 |
// } |
| 498 |
return DDialog::eventFilter(obj, e); |
| 499 |
} |
| 500 |
|