mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-20 15:17:41 +00:00
started new photo viewer
This commit is contained in:
parent
7fbc817b9e
commit
f62db48251
@ -1439,6 +1439,12 @@ emojiPanDuration: 200;
|
||||
emojiPanHover: #f0f0f0;
|
||||
emojiPanRound: 2px;
|
||||
|
||||
medviewNavBarWidth: 200px;
|
||||
medviewTopSkip: 50px;
|
||||
medviewBottomSkip: 50px;
|
||||
medviewLightOpacity: 0.75;
|
||||
medviewMinWidth: 600;
|
||||
|
||||
// Mac specific
|
||||
|
||||
macAccessoryHeight: 90;
|
||||
|
@ -1859,7 +1859,7 @@ namespace App {
|
||||
|
||||
setQuiting();
|
||||
if (wnd()) {
|
||||
wnd()->notifyClearFast();
|
||||
wnd()->quit();
|
||||
}
|
||||
if (app()) {
|
||||
app()->quit();
|
||||
|
100
Telegram/SourceFiles/mediaview.cpp
Normal file
100
Telegram/SourceFiles/mediaview.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
an unofficial desktop messaging app, see https://telegram.org
|
||||
|
||||
Telegram Desktop is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "lang.h"
|
||||
|
||||
#include "mediaview.h"
|
||||
#include "window.h"
|
||||
|
||||
MediaView::MediaView() : QWidget(App::wnd()),
|
||||
_photo(0), _maxWidth(0), _maxHeight(0), _x(0), _y(0), _w(0) {
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint | Qt::Tool | Qt::NoDropShadowWindowHint);
|
||||
moveToScreen();
|
||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
hide();
|
||||
}
|
||||
|
||||
void MediaView::moveToScreen() {
|
||||
QPoint wndCenter(App::wnd()->x() + App::wnd()->width() / 2, App::wnd()->y() + App::wnd()->height() / 2);
|
||||
QRect geom = QDesktopWidget().screenGeometry(wndCenter);
|
||||
if (geom != geometry()) {
|
||||
setGeometry(geom);
|
||||
}
|
||||
_maxWidth = width() - 2 * st::medviewNavBarWidth;
|
||||
_maxHeight = height() - st::medviewTopSkip - st::medviewBottomSkip;
|
||||
}
|
||||
|
||||
void MediaView::showPhoto(PhotoData *photo, const QRect &opaque) {
|
||||
_photo = photo;
|
||||
_opaqueRect = opaque;
|
||||
_photo->full->load();
|
||||
_w = photo->full->width();
|
||||
int h = photo->full->height();
|
||||
switch (cScale()) {
|
||||
case dbisOneAndQuarter: _w = qRound(float64(_w) * 1.25 - 0.01); h = qRound(float64(h) * 1.25 - 0.01); break;
|
||||
case dbisOneAndHalf: _w = qRound(float64(_w) * 1.5 - 0.01); h = qRound(float64(h) * 1.5 - 0.01); break;
|
||||
case dbisTwo: _w *= 2; h *= 2; break;
|
||||
}
|
||||
if (_w > _maxWidth) {
|
||||
h = qRound(h * _maxWidth / float64(_w));
|
||||
_w = _maxWidth;
|
||||
}
|
||||
if (h > _maxHeight) {
|
||||
_w = qRound(_w * _maxHeight / float64(h));
|
||||
h = _maxHeight;
|
||||
}
|
||||
_x = (width() - _w) / 2;
|
||||
_y = (height() - h) / 2;
|
||||
if (isHidden()) {
|
||||
moveToScreen();
|
||||
bool wm = testAttribute(Qt::WA_Mapped), wv = testAttribute(Qt::WA_WState_Visible);
|
||||
if (!wm) setAttribute(Qt::WA_Mapped, true);
|
||||
if (!wv) setAttribute(Qt::WA_WState_Visible, true);
|
||||
update();
|
||||
QEvent e(QEvent::UpdateRequest);
|
||||
event(&e);
|
||||
if (!wm) setAttribute(Qt::WA_Mapped, false);
|
||||
if (!wv) setAttribute(Qt::WA_WState_Visible, false);
|
||||
show();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void MediaView::paintEvent(QPaintEvent *e) {
|
||||
QPainter p(this);
|
||||
p.setOpacity(st::medviewLightOpacity);
|
||||
p.fillRect(QRect(0, 0, st::medviewNavBarWidth, height()), st::black->b);
|
||||
p.fillRect(QRect(width() - st::medviewNavBarWidth, 0, st::medviewNavBarWidth, height()), st::black->b);
|
||||
p.fillRect(QRect(st::medviewNavBarWidth, 0, width() - 2 * st::medviewNavBarWidth, height()), st::black->b);
|
||||
p.setOpacity(1);
|
||||
p.drawPixmap(_x, _y, (_photo->full->loaded() ? _photo->full : _photo->thumb)->pixNoCache(_w, 0, true));
|
||||
}
|
||||
|
||||
void MediaView::keyPressEvent(QKeyEvent *e) {
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
App::wnd()->layerHidden();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaView::mousePressEvent(QMouseEvent *e) {
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
App::wnd()->layerHidden();
|
||||
}
|
||||
}
|
43
Telegram/SourceFiles/mediaview.h
Normal file
43
Telegram/SourceFiles/mediaview.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
an unofficial desktop messaging app, see https://telegram.org
|
||||
|
||||
Telegram Desktop is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class MediaView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
MediaView();
|
||||
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
void showPhoto(PhotoData *photo, const QRect &opaque);
|
||||
void moveToScreen();
|
||||
|
||||
private:
|
||||
|
||||
QTimer _timer;
|
||||
PhotoData *_photo;
|
||||
QRect _opaqueRect;
|
||||
|
||||
int32 _maxWidth, _maxHeight, _x, _y, _w;
|
||||
|
||||
};
|
@ -29,6 +29,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
#include "layerwidget.h"
|
||||
#include "settingswidget.h"
|
||||
|
||||
#include "mediaview.h"
|
||||
|
||||
ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent), _shadow(st::boxShadow), _reconnect(this, QString()) {
|
||||
set(text, reconnect);
|
||||
connect(&_reconnect, SIGNAL(clicked()), this, SLOT(onReconnect()));
|
||||
@ -334,7 +336,7 @@ NotifyWindow::~NotifyWindow() {
|
||||
}
|
||||
|
||||
Window::Window(QWidget *parent) : PsMainWindow(parent),
|
||||
intro(0), main(0), settings(0), layer(0), layerBG(0), _topWidget(0),
|
||||
intro(0), main(0), settings(0), layer(0), layerBG(0), _topWidget(0), _mediaView(0),
|
||||
_connecting(0), _tempDeleter(0), _tempDeleterThread(0), myIcon(QPixmap::fromImage(icon256)), dragging(false), _inactivePress(false) {
|
||||
|
||||
if (objectName().isEmpty())
|
||||
@ -450,6 +452,8 @@ void Window::setupMain(bool anim) {
|
||||
fixOrder();
|
||||
|
||||
updateTitleStatus();
|
||||
|
||||
_mediaView = new MediaView();
|
||||
}
|
||||
|
||||
void Window::showSettings() {
|
||||
@ -549,7 +553,10 @@ void Window::showPhoto(const PhotoLink *lnk, HistoryItem *item) {
|
||||
|
||||
void Window::showPhoto(PhotoData *photo, HistoryItem *item) {
|
||||
layerHidden();
|
||||
layer = new LayerWidget(this, photo, item);
|
||||
_mediaView->showPhoto(photo, QRect());
|
||||
_mediaView->activateWindow();
|
||||
_mediaView->setFocus();
|
||||
// layer = new LayerWidget(this, photo, item);
|
||||
}
|
||||
|
||||
PhotoData *Window::photoShown() {
|
||||
@ -624,6 +631,7 @@ void Window::layerHidden() {
|
||||
layer = 0;
|
||||
if (layerBG) layerBG->deleteLater();
|
||||
layerBG = 0;
|
||||
if (_mediaView) _mediaView->hide();
|
||||
if (main) main->setInnerFocus();
|
||||
}
|
||||
|
||||
@ -920,6 +928,12 @@ void Window::onTempDirClearFailed() {
|
||||
emit tempDirClearFailed();
|
||||
}
|
||||
|
||||
void Window::quit() {
|
||||
delete _mediaView;
|
||||
_mediaView = 0;
|
||||
notifyClearFast();
|
||||
}
|
||||
|
||||
void Window::notifySchedule(History *history, MsgId msgId) {
|
||||
if (App::quiting() || !history->currentNotification()) return;
|
||||
|
||||
@ -1192,6 +1206,7 @@ void Window::notifyUpdateAllPhotos() {
|
||||
(*i)->updatePeerPhoto();
|
||||
}
|
||||
}
|
||||
if (_mediaView) _mediaView->update();
|
||||
}
|
||||
|
||||
void Window::notifyUpdateAll() {
|
||||
@ -1233,6 +1248,7 @@ Window::~Window() {
|
||||
delete _tempDeleter;
|
||||
delete _tempDeleterThread;
|
||||
delete _connecting;
|
||||
delete _mediaView;
|
||||
delete trayIcon;
|
||||
delete trayIconMenu;
|
||||
delete intro;
|
||||
|
@ -22,6 +22,7 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
#include "pspecific.h"
|
||||
#include "gui/boxshadow.h"
|
||||
|
||||
class MediaView;
|
||||
class TitleWidget;
|
||||
class IntroWidget;
|
||||
class MainWidget;
|
||||
@ -209,6 +210,8 @@ public:
|
||||
TempDirState tempDirState();
|
||||
void tempDirDelete();
|
||||
|
||||
void quit();
|
||||
|
||||
void notifySettingGot();
|
||||
void notifySchedule(History *history, MsgId msgId);
|
||||
void notifyClear(History *history = 0);
|
||||
@ -299,7 +302,7 @@ private:
|
||||
|
||||
NotifyWindows notifyWindows;
|
||||
|
||||
|
||||
MediaView *_mediaView;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -262,6 +262,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Debug\moc_mediaview.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Debug\moc_mtp.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@ -450,6 +454,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Deploy\moc_mediaview.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Deploy\moc_mtp.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@ -647,6 +655,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Release\moc_mediaview.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Release\moc_mtp.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
@ -768,6 +780,7 @@
|
||||
<ClCompile Include="SourceFiles\logs.cpp" />
|
||||
<ClCompile Include="SourceFiles\main.cpp" />
|
||||
<ClCompile Include="SourceFiles\mainwidget.cpp" />
|
||||
<ClCompile Include="SourceFiles\mediaview.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtp.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpConnection.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpDC.cpp" />
|
||||
@ -1385,6 +1398,20 @@
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="SourceFiles\mediaview.h">
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">Moc%27ing mediaview.h...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" "-fstdafx.h" "-f../../SourceFiles/mediaview.h" -DCUSTOM_API_ID -DUNICODE -D_WITH_DEBUG -DWIN32 -DWIN64 -DHAVE_STDINT_H -DZLIB_WINAPI -DQT_NO_DEBUG -DNDEBUG "-I.\..\..\Libraries\lzma\C" "-I.\..\..\Libraries\libexif-0.6.20" "-I.\..\..\Libraries\zlib-1.2.8" "-I.\..\..\Libraries\OpenSSL-Win32\include" "-I.\SourceFiles" "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I.\..\..\Libraries\QtStatic\qtbase\include\QtCore\5.3.1\QtCore" "-I.\..\..\Libraries\QtStatic\qtbase\include\QtGui\5.3.1\QtGui"</Command>
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing mediaview.h...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" "-fstdafx.h" "-f../../SourceFiles/mediaview.h" -DUNICODE -DWIN32 -DWIN64 -DHAVE_STDINT_H -DZLIB_WINAPI "-I.\..\..\Libraries\lzma\C" "-I.\..\..\Libraries\libexif-0.6.20" "-I.\..\..\Libraries\zlib-1.2.8" "-I.\..\..\Libraries\OpenSSL-Win32\include" "-I.\SourceFiles" "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I.\..\..\Libraries\QtStatic\qtbase\include\QtCore\5.3.1\QtCore" "-I.\..\..\Libraries\QtStatic\qtbase\include\QtGui\5.3.1\QtGui"</Command>
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Moc%27ing mediaview.h...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" "-fstdafx.h" "-f../../SourceFiles/mediaview.h" -DUNICODE -D_WITH_DEBUG -DWIN32 -DWIN64 -DHAVE_STDINT_H -DZLIB_WINAPI -DQT_NO_DEBUG -DNDEBUG "-I.\..\..\Libraries\lzma\C" "-I.\..\..\Libraries\libexif-0.6.20" "-I.\..\..\Libraries\zlib-1.2.8" "-I.\..\..\Libraries\OpenSSL-Win32\include" "-I.\SourceFiles" "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I.\..\..\Libraries\QtStatic\qtbase\include\QtCore\5.3.1\QtCore" "-I.\..\..\Libraries\QtStatic\qtbase\include\QtGui\5.3.1\QtGui"</Command>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="SourceFiles\mtproto\mtpAuthKey.h" />
|
||||
<CustomBuild Include="SourceFiles\mtproto\mtpFileLoader.h">
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing mtpFileLoader.h...</Message>
|
||||
|
@ -668,6 +668,18 @@
|
||||
<ClCompile Include="GeneratedFiles\Release\moc_switcher.cpp">
|
||||
<Filter>Generated Files\Release</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SourceFiles\mediaview.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Deploy\moc_mediaview.cpp">
|
||||
<Filter>Generated Files\Deploy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Debug\moc_mediaview.cpp">
|
||||
<Filter>Generated Files\Debug</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeneratedFiles\Release\moc_mediaview.cpp">
|
||||
<Filter>Generated Files\Release</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="SourceFiles\stdafx.h">
|
||||
@ -906,6 +918,9 @@
|
||||
<CustomBuild Include="SourceFiles\gui\switcher.h">
|
||||
<Filter>gui</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="SourceFiles\mediaview.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="SourceFiles\art\iconround256.ico" />
|
||||
|
Loading…
Reference in New Issue
Block a user