~ubuntu-branches/ubuntu/karmic/choqok/karmic

« back to all changes in this revision

Viewing changes to src/statustextedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Christian Mangold
  • Date: 2009-08-11 22:29:59 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090811222959-7tnr98ptcnyx3pjg
Tags: 0.6.6-0ubuntu1
[Alessandro Ghersi]
* New upstream release
  - Bump Standards-Version to 3.8.2
  - Long description formatted to fit in 80 characters

[Christian Mangold]
* Improve long description
* Update Maintainer, package is in main now
* Add a watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of Choqok, the KDE micro-blogging client
3
 
 
4
 
    Copyright (C) 2008-2009 Mehrdad Momeny <mehrdad.momeny@gmail.com>
5
 
 
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.
13
 
 
14
 
 
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.
19
 
 
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/
22
 
 
23
 
*/
24
 
#include "statustextedit.h"
25
 
#include <QKeyEvent>
26
 
#include <KDE/KLocale>
27
 
 
28
 
#include "backend.h"
29
 
#include <settings.h>
30
 
#include <QMenu>
31
 
 
32
 
StatusTextEdit::StatusTextEdit( QWidget *parent )
33
 
        : KTextEdit( parent )
34
 
{
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." ) );
40
 
}
41
 
 
42
 
StatusTextEdit::~StatusTextEdit()
43
 
{
44
 
}
45
 
 
46
 
void StatusTextEdit::keyPressEvent( QKeyEvent * e )
47
 
{
48
 
    if (( e->key() == Qt::Key_Return ) || ( e->key() == Qt::Key_Enter ) ) {
49
 
        QString txt = toPlainText();
50
 
        emit returnPressed( txt );
51
 
        e->accept();
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() ) {
59
 
            this->clear();
60
 
            setDefaultDirection( dir );
61
 
            emit cleared();
62
 
            e->accept();
63
 
        } else {
64
 
            KTextEdit::keyPressEvent( e );
65
 
        }
66
 
    } else {
67
 
        KTextEdit::keyPressEvent( e );
68
 
    }
69
 
}
70
 
 
71
 
void StatusTextEdit::insertFromMimeData ( const QMimeData *source )
72
 
{
73
 
    if( Settings::shortenOnPaste() )
74
 
        KTextEdit::insertPlainText( Backend::prepareStatus( source->text() ) );
75
 
    else
76
 
        KTextEdit::insertPlainText( source->text() );
77
 
}
78
 
 
79
 
void StatusTextEdit::setDefaultDirection( Qt::LayoutDirection dir )
80
 
{
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 );
87
 
}
88
 
 
89
 
void StatusTextEdit::setNumOfCharsLeft()
90
 
{
91
 
    mCountOfRemainsChars = 140 - toPlainText().count();
92
 
    emit charsLeft( mCountOfRemainsChars );
93
 
}
94
 
 
95
 
void StatusTextEdit::clearContentsAndSetDirection( Qt::LayoutDirection dir )
96
 
{
97
 
    QString tmp = this->toPlainText();
98
 
    if ( !tmp.isEmpty() ) {
99
 
        prevStr = this->toHtml();
100
 
        this->clear();
101
 
    }
102
 
    setDefaultDirection( dir );
103
 
}
104
 
 
105
 
int StatusTextEdit::countOfRemainsChar() const
106
 
{
107
 
    return mCountOfRemainsChars;
108
 
}
109
 
 
110
 
#include "statustextedit.moc"