Skip to content

Commit

Permalink
adaptive layout checkbox added to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Feb 21, 2016
1 parent fb0f297 commit fc9d75b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/facades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ namespace Sandbox {
struct GlobalDataStruct {
uint64 LaunchId = 0;
Adaptive::Layout AdaptiveLayout = Adaptive::NormalLayout;
bool AdaptiveForWide = true;
};
GlobalDataStruct *GlobalData = 0;

Expand All @@ -370,5 +371,6 @@ namespace Global {

DefineReadOnlyVar(Global, uint64, LaunchId);
DefineVar(Global, Adaptive::Layout, AdaptiveLayout);
DefineVar(Global, bool, AdaptiveForWide);

};
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/facades.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ namespace Global {

DeclareReadOnlyVar(uint64, LaunchId);
DeclareVar(Adaptive::Layout, AdaptiveLayout);
DeclareVar(bool, AdaptiveForWide);

};

Expand All @@ -150,6 +151,6 @@ namespace Adaptive {
return Global::AdaptiveLayout() == NormalLayout;
}
inline bool Wide() {
return Global::AdaptiveLayout() == WideLayout;
return Global::AdaptiveForWide() && (Global::AdaptiveLayout() == WideLayout);
}
}
1 change: 1 addition & 0 deletions Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4690,6 +4690,7 @@ void HistoryWidget::doneShow() {

void HistoryWidget::updateAdaptiveLayout() {
_sideShadow.setVisible(!Adaptive::OneColumn());
update();
}

void HistoryWidget::animStop() {
Expand Down
9 changes: 9 additions & 0 deletions Telegram/SourceFiles/localstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ namespace {
}
} break;

case dbiAdaptiveForWide: {
qint32 v;
stream >> v;
if (!_checkStreamStatus(stream)) return false;

Global::SetAdaptiveForWide(v == 1);
} break;

case dbiAutoLock: {
qint32 v;
stream >> v;
Expand Down Expand Up @@ -1506,6 +1514,7 @@ namespace {
EncryptedDescriptor data(size);
data.stream << quint32(dbiSendKey) << qint32(cCtrlEnter() ? dbiskCtrlEnter : dbiskEnter);
data.stream << quint32(dbiTileBackground) << qint32(cTileBackground() ? 1 : 0);
data.stream << quint32(dbiAdaptiveForWide) << qint32(Global::AdaptiveForWide() ? 1 : 0);
data.stream << quint32(dbiAutoLock) << qint32(cAutoLock());
data.stream << quint32(dbiReplaceEmojis) << qint32(cReplaceEmojis() ? 1 : 0);
data.stream << quint32(dbiDefaultAttach) << qint32(cDefaultAttach());
Expand Down
36 changes: 34 additions & 2 deletions Telegram/SourceFiles/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ SettingsInner::SettingsInner(SettingsWidget *parent) : TWidget(parent)
, _backFromGallery(this, lang(lng_settings_bg_from_gallery))
, _backFromFile(this, lang(lng_settings_bg_from_file))
, _tileBackground(this, lang(lng_settings_bg_tile), cTileBackground())
, _adaptiveForWide(this, lang(lng_settings_adaptive_wide), Global::AdaptiveForWide())
, _needBackgroundUpdate(false)

// advanced
Expand Down Expand Up @@ -310,6 +311,7 @@ SettingsInner::SettingsInner(SettingsWidget *parent) : TWidget(parent)
connect(&_backFromGallery, SIGNAL(clicked()), this, SLOT(onBackFromGallery()));
connect(&_backFromFile, SIGNAL(clicked()), this, SLOT(onBackFromFile()));
connect(&_tileBackground, SIGNAL(changed()), this, SLOT(onTileBackground()));
connect(&_adaptiveForWide, SIGNAL(changed()), this, SLOT(onAdaptiveForWide()));

// advanced
connect(&_passcodeEdit, SIGNAL(clicked()), this, SLOT(onPasscode()));
Expand Down Expand Up @@ -635,6 +637,10 @@ void SettingsInner::paintEvent(QPaintEvent *e) {
top += st::setBackgroundSize;
top += st::setLittleSkip;
top += _tileBackground.height();
if (Global::AdaptiveLayout() == Adaptive::WideLayout) {
top += st::setLittleSkip;
top += _adaptiveForWide.height();
}
}

// advanced
Expand Down Expand Up @@ -753,6 +759,10 @@ void SettingsInner::resizeEvent(QResizeEvent *e) {

top += st::setLittleSkip;
_tileBackground.move(_left, top); top += _tileBackground.height();
if (Global::AdaptiveLayout() == Adaptive::WideLayout) {
top += st::setLittleSkip;
_adaptiveForWide.move(_left, top); top += _adaptiveForWide.height();
}
}

// advanced
Expand Down Expand Up @@ -855,6 +865,11 @@ void SettingsInner::mousePressEvent(QMouseEvent *e) {
void SettingsInner::contextMenuEvent(QContextMenuEvent *e) {
}

void SettingsInner::updateAdaptiveLayout() {
showAll();
resizeEvent(0);
}

void SettingsInner::step_photo(float64 ms, bool timer) {
float64 dt = ms / st::setPhotoDuration;
if (dt >= 1) {
Expand Down Expand Up @@ -1093,10 +1108,16 @@ void SettingsInner::showAll() {
_backFromGallery.show();
_backFromFile.show();
_tileBackground.show();
if (Global::AdaptiveLayout() == Adaptive::WideLayout) {
_adaptiveForWide.show();
} else {
_adaptiveForWide.hide();
}
} else {
_backFromGallery.hide();
_backFromFile.hide();
_tileBackground.hide();
_adaptiveForWide.hide();
}

// advanced
Expand Down Expand Up @@ -1628,6 +1649,16 @@ void SettingsInner::onTileBackground() {
}
}

void SettingsInner::onAdaptiveForWide() {
if (Global::AdaptiveForWide() != _adaptiveForWide.checked()) {
Global::SetAdaptiveForWide(_adaptiveForWide.checked());
if (App::wnd()) {
App::wnd()->updateAdaptiveLayout();
}
Local::writeUserSettings();
}
}

void SettingsInner::onDontAskDownloadPath() {
cSetAskDownloadPath(!_dontAskDownloadPath.checked());
Local::writeUserSettings();
Expand Down Expand Up @@ -1898,10 +1929,11 @@ void SettingsWidget::updateAdaptiveLayout() {
} else {
_close.show();
}
_inner.updateAdaptiveLayout();
resizeEvent(0);
}

void SettingsWidget::updateDisplayNotify()
{
void SettingsWidget::updateDisplayNotify() {
_inner.enableDisplayNotify(cDesktopNotify());
}

Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/settingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SettingsInner : public TWidget, public RPCSender {
void mousePressEvent(QMouseEvent *e);
void contextMenuEvent(QContextMenuEvent *e);

void updateAdaptiveLayout();

void step_photo(float64 ms, bool timer);

void updateSize(int32 newWidth);
Expand Down Expand Up @@ -156,6 +158,7 @@ public slots:
void onBackFromGallery();
void onBackFromFile();
void onTileBackground();
void onAdaptiveForWide();

void onLocalStorageClear();

Expand Down Expand Up @@ -273,7 +276,7 @@ public slots:
// chat background
QPixmap _background;
LinkButton _backFromGallery, _backFromFile;
FlatCheckbox _tileBackground;
FlatCheckbox _tileBackground, _adaptiveForWide;
bool _needBackgroundUpdate;

// advanced
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ enum DataBlockId {
dbiSavedGifsLimit = 0x35,
dbiShowingSavedGifs = 0x36,
dbiAutoPlay = 0x37,
dbiAdaptiveForWide = 0x38,

dbiEncryptedWithSalt = 333,
dbiEncrypted = 444,
Expand Down

1 comment on commit fc9d75b

@martijnrondeel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.