Skip to content

Commit

Permalink
photos overview blur, multimonitor photoview fix, os x file dialog de…
Browse files Browse the repository at this point in the history
…fault path
  • Loading branch information
john-preston committed Sep 22, 2014
1 parent af9117e commit 4064113
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/boxes/downloadpathbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ void DownloadPathBox::onEditPath() {

filedialogInit();
QString path, lastPath = cDialogLastPath();
if (!cDownloadPath().isEmpty()) cSetDialogLastPath(cDownloadPath());
if (!cDownloadPath().isEmpty()) {
cSetDialogLastPath(cDownloadPath());
}
if (filedialogGetDir(path, lang(lng_download_path_choose))) {
if (!path.isEmpty()) {
_path = path + '/';
Expand Down
12 changes: 10 additions & 2 deletions Telegram/SourceFiles/gui/filedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
#include "application.h"

void filedialogInit() {
// hack to restore previous dir without hurting performance
if (cDialogLastPath().isEmpty()) {
#ifdef Q_OS_WIN
// hack to restore previous dir without hurting performance
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
settings.beginGroup(QLatin1String("Qt"));
QByteArray sd = settings.value(QLatin1String("filedialog")).toByteArray();
Expand Down Expand Up @@ -59,16 +60,21 @@ void filedialogInit() {
cSetDialogHelperPath(temppath.absolutePath());
}
}
#else
cSetDialogLastPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
#endif
}
}

// multipleFiles: 1 - multi open, 0 - single open, -1 - single save, -2 - select dir
bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, int multipleFiles, const QString &startFile = QString()) {
bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, int multipleFiles, QString startFile = QString()) {
#if defined Q_OS_LINUX || defined Q_OS_MAC // use native
remoteContent = QByteArray();
QString file;
if (multipleFiles >= 0) {
files = QFileDialog::getOpenFileNames(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
QString path = files.isEmpty() ? QString() : QFileInfo(files.back()).absoluteDir().absolutePath();
if (!path.isEmpty()) cSetDialogLastPath(path);
return !files.isEmpty();
} else if (multipleFiles < -1) {
file = QFileDialog::getExistingDirectory(App::wnd() ? App::wnd()->filedialogParent() : 0, caption);
Expand All @@ -81,6 +87,8 @@ bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QS
files = QStringList();
return false;
} else {
QString path = QFileInfo(file).absoluteDir().absolutePath();
if (!path.isEmpty()) cSetDialogLastPath(path);
files = QStringList(file);
return true;
}
Expand Down
45 changes: 24 additions & 21 deletions Telegram/SourceFiles/gui/images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ namespace {
}
}

QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const {
restore();
loaded();

const QPixmap &p(pixData());
if (p.isNull()) return blank()->pix();

QImage img = p.toImage();
QImage imageBlur(QImage img) {
QImage::Format fmt = img.format();
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_ARGB32 && fmt != QImage::Format_ARGB32_Premultiplied) {
QImage tmp(img.width(), img.height(), QImage::Format_ARGB32);
Expand Down Expand Up @@ -153,10 +146,10 @@ QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const {
x = 0;

#define update(start, middle, end) \
rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FFLL; \
rgballsum += _blurGetColors(&pix[yw + (start) * 4]) - 2 * _blurGetColors(&pix[yw + (middle) * 4]) + _blurGetColors(&pix[yw + (end) * 4]); \
rgbsum += rgballsum; \
x++;
rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FFLL; \
rgballsum += _blurGetColors(&pix[yw + (start) * 4]) - 2 * _blurGetColors(&pix[yw + (middle) * 4]) + _blurGetColors(&pix[yw + (end) * 4]); \
rgbsum += rgballsum; \
x++;

while (x < r1) {
update(0, x, x + r1);
Expand Down Expand Up @@ -186,14 +179,14 @@ QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const {
int yi = x * 4;

#define update(start, middle, end) \
uint64 res = rgbsum >> 6; \
pix[yi] = res & 0xFF; \
pix[yi + 1] = (res >> 16) & 0xFF; \
pix[yi + 2] = (res >> 32) & 0xFF; \
rgballsum += rgb[x + (start) * w] - 2 * rgb[x + (middle) * w] + rgb[x + (end) * w]; \
rgbsum += rgballsum; \
y++; \
yi += stride;
uint64 res = rgbsum >> 6; \
pix[yi] = res & 0xFF; \
pix[yi + 1] = (res >> 16) & 0xFF; \
pix[yi + 2] = (res >> 32) & 0xFF; \
rgballsum += rgb[x + (start) * w] - 2 * rgb[x + (middle) * w] + rgb[x + (end) * w]; \
rgbsum += rgballsum; \
y++; \
yi += stride;

while (y < r1) {
update(0, y, y + r1);
Expand All @@ -207,11 +200,21 @@ QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const {

#undef update
}

delete[] rgb;
}
}
return img;
}

QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const {
restore();
loaded();

const QPixmap &p(pixData());
if (p.isNull()) return blank()->pix();

QImage img = imageBlur(p.toImage());
if (h <= 0) {
img = img.scaledToWidth(w, Qt::SmoothTransformation);
} else {
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/gui/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com

#include <QtGui/QPixmap>

QImage imageBlur(QImage img);

class Image {
public:

Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ void HistoryAudio::draw(QPainter &p, const HistoryItem *parent, bool selected, i
p.setPen(status->p);
if (already || hasdata) {
if (playing == data && playingState != VoiceMessageStopped) {
statusText = formatDurationText(playingPosition / AudioVoiceMsgFrequency);
statusText = formatDurationText(playingPosition / AudioVoiceMsgFrequency) + qsl(" / ") + formatDurationText(playingDuration / AudioVoiceMsgFrequency);
} else {
statusText = formatDurationText(data->duration);
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ QString HistoryList::getSelectedText() const {
void HistoryList::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
historyWidget->onClearSelected();
} else if (e == QKeySequence::Copy && !_selected.isEmpty() && _selected.cbegin().value() != FullItemSel) {
} else if (e == QKeySequence::Copy && !_selected.isEmpty()) {
copySelectedText();
} else if (e == QKeySequence::Delete) {
historyWidget->onDeleteSelected();
Expand Down
6 changes: 6 additions & 0 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,15 @@ void MainWidget::setInnerFocus() {
if (hider || !history.peer()) {
if (hider && hider->wasOffered()) {
hider->setFocus();
} else if (overview) {
overview->activate();
} else if (profile) {
profile->activate();
} else {
dialogs.setInnerFocus();
}
} else if (profile) {
profile->setFocus();
} else {
history.activate();
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/mediaview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void MediaView::moveToScreen() {
}
if (!geom.contains(_avail)) {
_avail = geom;
_avail.moveTo(0, 0);
}
_avail.moveTo(_avail.x() - geom.x(), _avail.y() - geom.y());
_maxWidth = _avail.width() - 2 * st::medviewNavBarWidth;
_maxHeight = _avail.height() - st::medviewTopSkip - st::medviewBottomSkip;
_leftNav = QRect(0, 0, st::medviewNavBarWidth, height());
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/overviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ void OverviewInner::clear() {
QPixmap OverviewInner::genPix(PhotoData *photo, int32 size) {
size *= cIntRetinaFactor();
QImage img = (photo->full->loaded() ? photo->full : (photo->medium->loaded() ? photo->medium : photo->thumb))->pix().toImage();
if (!photo->full->loaded() && !photo->medium->loaded()) {
img = imageBlur(img);
}
if (img.width() > img.height()) {
img = img.scaled(img.width() * size / img.height(), size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright (c) 2014 John Preston, https://tdesktop.com

extern bool gDebug;
inline bool cDebug() {
#ifdef _DEBUG
#if defined _DEBUG && !defined Q_OS_MAC
return true;
#elif defined _WITH_DEBUG
return gDebug;
Expand Down

0 comments on commit 4064113

Please sign in to comment.