From 789570a9ec1b0f75870bca747d6a8e14ab452ba7 Mon Sep 17 00:00:00 2001 From: leha-bot Date: Sun, 18 Aug 2019 21:44:02 +0300 Subject: [PATCH] data_document: extract Q_FIXED to impl from .h WIP. Related to #240. --- Telegram/CMakeLists.txt | 1 + Telegram/SourceFiles/data/data_document.cpp | 37 +++++++++++++++++++++ Telegram/SourceFiles/data/data_document.h | 13 +++----- 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 Telegram/SourceFiles/data/data_document.cpp diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 36351cc47..36ab4c50b 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -258,6 +258,7 @@ add_executable(Kepka WIN32 MACOSX_BUNDLE SourceFiles/core/utils.cpp SourceFiles/data/data_abstract_structure.cpp + SourceFiles/data/data_document.cpp SourceFiles/data/data_drafts.cpp SourceFiles/data/data_game.cpp SourceFiles/data/data_photo.cpp diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp new file mode 100644 index 000000000..d2814a236 --- /dev/null +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -0,0 +1,37 @@ +// +// This file is part of Kepka, +// an unofficial desktop version of Telegram messaging app, +// see https://github.com/procxx/kepka +// +// Kepka 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. +// +// In addition, as a special exception, the copyright holders give permission +// to link the code of portions of this program with the OpenSSL library. +// +// Full license: https://github.com/procxx/kepka/blob/master/LICENSE +// Copyright (c) 2019- Kepka Contributors, https://github.com/procxx +// +/// @file data/data_document.cpp Implementation and internals (and Qt QFixed) +/// @todo Get rid of QFixed. + +#include "data/data_document.h" +#include "private/qfixed_p.h" +#include + +void MessageCursor::fillFrom(const QTextEdit *edit) { + QTextCursor c = edit->textCursor(); + position = c.position(); + anchor = c.anchor(); + QScrollBar *s = edit->verticalScrollBar(); + scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX; +} + +const int MessageCursor::kMaxScroll = QFIXED_MAX; diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index cb0f561bb..78506e60e 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -37,7 +37,7 @@ #include "scheme.h" -#include "private/qfixed_p.h" // QFIXED_MAX, warn: temporary, should be eliminated. +class QTextEdit; class HistoryItem; @@ -522,6 +522,7 @@ QString saveFileName(const QString &title, const QString &filter, const QString MsgId clientMsgId(); struct MessageCursor { + static const int kMaxScroll; MessageCursor() = default; MessageCursor(int position, int anchor, int scroll) : position(position) @@ -530,13 +531,7 @@ struct MessageCursor { MessageCursor(const QTextEdit *edit) { fillFrom(edit); } - void fillFrom(const QTextEdit *edit) { - QTextCursor c = edit->textCursor(); - position = c.position(); - anchor = c.anchor(); - QScrollBar *s = edit->verticalScrollBar(); - scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX; - } + void fillFrom(const QTextEdit *edit); void applyTo(QTextEdit *edit) { auto cursor = edit->textCursor(); cursor.setPosition(anchor, QTextCursor::MoveAnchor); @@ -548,7 +543,7 @@ struct MessageCursor { } int position = 0; int anchor = 0; - int scroll = QFIXED_MAX; + int scroll = kMaxScroll; }; inline bool operator==(const MessageCursor &a, const MessageCursor &b) {