Skip to content

Commit

Permalink
data_document: extract Q_FIXED to impl from .h
Browse files Browse the repository at this point in the history
WIP.
Related to #240.
  • Loading branch information
leha-bot committed Aug 18, 2019
1 parent 0e41fbf commit 789570a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions Telegram/SourceFiles/data/data_document.cpp
Original file line number Diff line number Diff line change
@@ -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 <QTextEdit>

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;
13 changes: 4 additions & 9 deletions Telegram/SourceFiles/data/data_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "scheme.h"

#include "private/qfixed_p.h" // QFIXED_MAX, warn: temporary, should be eliminated.
class QTextEdit;

class HistoryItem;

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 789570a

Please sign in to comment.