2
This file is part of Choqok, the KDE micro-blogging client
4
Copyright (C) 2008-2009 Mehrdad Momeny <mehrdad.momeny@gmail.com>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, see http://www.gnu.org/licenses/
24
#include "statustextedit.h"
26
#include <KDE/KLocale>
32
StatusTextEdit::StatusTextEdit( QWidget *parent )
35
this->setAcceptRichText( false );
36
connect( this, SIGNAL( textChanged() ), this, SLOT( setNumOfCharsLeft() ) );
37
setAcceptRichText( false );
38
this->setToolTip( i18n( "<strong>Note:</strong><br/><em>Ctrl+P</em> to have the previous text submitted.<br/>\
39
<em>Ctrl+S</em> to enable/disable Auto spell checker." ) );
42
StatusTextEdit::~StatusTextEdit()
46
void StatusTextEdit::keyPressEvent( QKeyEvent * e )
48
if (( e->key() == Qt::Key_Return ) || ( e->key() == Qt::Key_Enter ) ) {
49
QString txt = toPlainText();
50
emit returnPressed( txt );
52
} else if ( e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_S ) {
53
this->setCheckSpellingEnabled( !this->checkSpellingEnabled() );
54
} else if ( e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_P ) {
55
QString tmp = this->toHtml();
56
this->setHtml( tmp + ' ' + prevStr );
57
} else if ( e->key() == Qt::Key_Escape ) {
58
if ( !this->toPlainText().isEmpty() ) {
60
setDefaultDirection( dir );
64
KTextEdit::keyPressEvent( e );
67
KTextEdit::keyPressEvent( e );
71
void StatusTextEdit::insertFromMimeData ( const QMimeData *source )
73
if( Settings::shortenOnPaste() )
74
KTextEdit::insertPlainText( Backend::prepareStatus( source->text() ) );
76
KTextEdit::insertPlainText( source->text() );
79
void StatusTextEdit::setDefaultDirection( Qt::LayoutDirection dir )
81
QTextCursor c = this->textCursor();
82
QTextBlockFormat f = c.blockFormat();
83
f.setLayoutDirection( dir );
84
c.setBlockFormat( f );
85
this->setTextCursor( c );
86
this->setFocus( Qt::OtherFocusReason );
89
void StatusTextEdit::setNumOfCharsLeft()
91
mCountOfRemainsChars = 140 - toPlainText().count();
92
emit charsLeft( mCountOfRemainsChars );
95
void StatusTextEdit::clearContentsAndSetDirection( Qt::LayoutDirection dir )
97
QString tmp = this->toPlainText();
98
if ( !tmp.isEmpty() ) {
99
prevStr = this->toHtml();
102
setDefaultDirection( dir );
105
int StatusTextEdit::countOfRemainsChar() const
107
return mCountOfRemainsChars;
110
#include "statustextedit.moc"