Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enabled zoom slider for notes widget #1608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/modules/windows/notes/NotesContentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ namespace Otter
{

NotesContentsWidget::NotesContentsWidget(const QVariantMap &parameters, Window *window, QWidget *parent) : ContentsWidget(parameters, window, parent),
m_ui(new Ui::NotesContentsWidget)
m_ui(new Ui::NotesContentsWidget),
m_zoom(100)
{
m_ui->setupUi(this);
m_ui->filterLineEditWidget->setClearOnEscape(true);

m_defaultFont = m_ui->textEditWidget->font();

QMenu *addMenu(new QMenu(m_ui->addButton));
addMenu->addAction(ThemesManager::createIcon(QLatin1String("inode-directory")), tr("Add Folder…"), this, &NotesContentsWidget::addFolder);
addMenu->addAction(tr("Add Note"), this, &NotesContentsWidget::addNote);
Expand Down Expand Up @@ -263,6 +266,20 @@ void NotesContentsWidget::triggerAction(int identifier, const QVariantMap &param
}
}

void NotesContentsWidget::setZoom(int zoom)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it is the best way to implement it, perhaps it could be achieved using QPlainTextEdit::zoomIn() and QPlainTextEdit::zoomOut(), but this API is kind of crappy. :-/
Anyway, I think that zooming should be implemented in TextEditWidget (adding getZoom() and setZoom()).
Also, using just point size might be risky, since AFAIR it can return 0, we might consider some method in Utils to apply zoom to fonts.

{
if (zoom != m_zoom)
{
m_zoom = zoom;

QFont font(m_defaultFont);
font.setPointSize(qRound(font.pointSize() * (static_cast<qreal>(zoom) / 100)));
m_ui->textEditWidget->setFont(font);

emit zoomChanged(zoom);
}
}

void NotesContentsWidget::updateActions()
{
const QModelIndex index(m_ui->notesViewWidget->getCurrentIndex());
Expand Down Expand Up @@ -428,4 +445,14 @@ bool NotesContentsWidget::eventFilter(QObject *object, QEvent *event)
return ContentsWidget::eventFilter(object, event);
}

bool NotesContentsWidget::canZoom() const
{
return true;
}

int NotesContentsWidget::getZoom() const
{
return m_zoom;
}

}
5 changes: 5 additions & 0 deletions src/modules/windows/notes/NotesContentsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class NotesContentsWidget final : public ContentsWidget
QIcon getIcon() const override;
ActionsManager::ActionDefinition::State getActionState(int identifier, const QVariantMap &parameters = {}) const override;
bool eventFilter(QObject *object, QEvent *event) override;
virtual bool canZoom() const override;
Copy link
Member

Choose a reason for hiding this comment

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

There should be no virtual keyword here, and methods returning bool values should go after these returningint values.

int getZoom() const override;

public slots:
void triggerAction(int identifier, const QVariantMap &parameters = {}, ActionsManager::TriggerType trigger = ActionsManager::UnknownTrigger) override;
void setZoom(int zoom) override;

protected:
void changeEvent(QEvent *event) override;
Expand All @@ -71,6 +74,8 @@ protected slots:

private:
Ui::NotesContentsWidget *m_ui;
int m_zoom;
QFont m_defaultFont;
};

}
Expand Down