Skip to content

Commit

Permalink
WIP: smallscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Sep 8, 2023
1 parent 831631e commit 901f53a
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/desktop/chat/chatbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ChatBox::ChatBox(Document *doc, QWidget *parent)
connect(m_chatWidget, &ChatWidget::message, this, &ChatBox::message);
connect(m_chatWidget, &ChatWidget::detachRequested, this, &ChatBox::detachFromParent);
connect(m_chatWidget, &ChatWidget::expandRequested, this, [this]() {
if(m_state == State::Collapsed) {
if(isCollapsed()) {
emit expandPlease();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/chat/chatbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChatBox final : public QWidget
//! Focus the text input widget
void focusInput();

bool isCollapsed() const { return m_state == State::Collapsed; }
bool isCollapsed() const { return m_state == State::Collapsed || !isVisible(); }

private slots:
void onCanvasChanged(canvas::CanvasModel *canvas);
Expand Down
4 changes: 2 additions & 2 deletions src/desktop/chat/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ ChatWidget::ChatWidget(QWidget *parent)
d->compactAction->setChecked(d->compactMode);
}

if(ALLOW_DETACH) {
if(ALLOW_DETACH && !dpApp().smallScreenMode()) {
d->attachAction = d->externalMenu->addAction(
tr("Attach"), this, &ChatWidget::attach);
d->detachAction = d->externalMenu->addAction(
Expand Down Expand Up @@ -854,7 +854,7 @@ void ChatWidget::showChatContextMenu(const QPoint &pos)

void ChatWidget::contextMenuAboutToShow()
{
if(ALLOW_DETACH) {
if(ALLOW_DETACH && !dpApp().smallScreenMode()) {
d->attachAction->setVisible(!d->isAttached);
d->detachAction->setVisible(d->isAttached);
}
Expand Down
9 changes: 9 additions & 0 deletions src/desktop/dialogs/settingsdialog/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ void General::initMiscUi(desktop::settings::Settings &settings, utils::SanerForm
settings.bindConfirmLayerDelete(confirmDelete);
form->addRow(nullptr, confirmDelete);

auto *interfaceMode = form->addRadioGroup(nullptr, true, {
{ tr("Standard Mode"), int(desktop::settings::InterfaceMode::Standard) },
{ tr("Small Screen Mode"), int(desktop::settings::InterfaceMode::SmallScreen) }
});
settings.bindInterfaceMode(interfaceMode);
form->addRow(nullptr, utils::note(
tr("Changes to the interface mode apply after you restart Drawpile."),
QSizePolicy::Label));

form->addSeparator();

auto *enableLogging = new QCheckBox(tr("Write debugging log to file"));
Expand Down
27 changes: 26 additions & 1 deletion src/desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QDir>
#include <QIcon>
#include <QMetaEnum>
#include <QScreen>
#include <QStyle>
#include <QStyleFactory>
#include <QUrl>
Expand Down Expand Up @@ -273,6 +274,28 @@ void DrawpileApp::initTheme()
updateThemeIcons();
}

void DrawpileApp::initInterfaceMode()
{
if(m_settings.interfaceMode() == int(desktop::settings::InterfaceMode::Unknown)) {
m_settings.setInterfaceMode(int(guessInterfaceMode()));
}
m_smallScreenMode = m_settings.interfaceMode() == int(desktop::settings::InterfaceMode::SmallScreen);
}

desktop::settings::InterfaceMode DrawpileApp::guessInterfaceMode()
{
#ifdef Q_OS_ANDROID
QScreen *screen = primaryScreen();
if(screen) {
QSize size = screen->availableVirtualSize();
if(size.width() < 720 || size.height() < 720) {
return desktop::settings::InterfaceMode::SmallScreen;
}
}
#endif
return desktop::settings::InterfaceMode::Standard;
}

void DrawpileApp::openUrl(QUrl url)
{
// See if there is an existing replacable window
Expand Down Expand Up @@ -453,8 +476,10 @@ static std::tuple<QStringList, QString> initApp(DrawpileApp &app)
#endif

app.initState();
app.settings().bindWriteLogFile(&utils::enableLogFile);
desktop::settings::Settings &settings = app.settings();
settings.bindWriteLogFile(&utils::enableLogFile);
app.initTheme();
app.initInterfaceMode();

#ifdef Q_OS_MACOS
// Mac specific settings
Expand Down
6 changes: 6 additions & 0 deletions src/desktop/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Q_OBJECT
void setThemeStyle(const QString &themeStyle);
void setThemePalette(desktop::settings::ThemePalette themePalette);
void initTheme();
void initInterfaceMode();

void openUrl(QUrl url);

Expand All @@ -44,6 +45,8 @@ Q_OBJECT
const utils::Recents &recents() const { return *m_recents; }
utils::Recents &recents() { return *m_recents; }

bool smallScreenMode() const { return m_smallScreenMode; }

signals:
void eraserNear(bool near);
void setDockTitleBarsHidden(bool hidden);
Expand All @@ -54,6 +57,7 @@ Q_OBJECT

private:
desktop::settings::Settings m_settings;
bool m_smallScreenMode;
utils::StateDatabase *m_state = nullptr;
utils::Recents *m_recents = nullptr;
QMap<notification::Event, QSoundEffect*> m_sounds;
Expand All @@ -62,6 +66,8 @@ Q_OBJECT

void updateThemeIcons();

desktop::settings::InterfaceMode guessInterfaceMode();

QPalette loadPalette(const QString &file);
};

Expand Down
Loading

0 comments on commit 901f53a

Please sign in to comment.