117
147
else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ShiftButton))
119
else if(e->key() == Key_U && (e->state() & ControlButton))
149
else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ControlButton))
121
151
else if(e->key() == Key_C && (e->state() & ControlButton) && !hasSelectedText())
124
154
QTextEdit::keyPressEvent(e);
157
//----------------------------------------------------------------------------
159
//----------------------------------------------------------------------------
160
LineEdit::LineEdit( QWidget *parent, const char *name )
161
: ChatEdit( parent, name )
163
lastSize = QSize( 0, 0 );
164
initialWindowGeometry = QRect( 0, 0, 0, 0 );
166
QWidget *topParent = topLevelWidget();
167
topParent->installEventFilter( this );
168
moveTo = QPoint(topParent->x(), topParent->y());
170
moveTimer = new QTimer( this );
171
connect( moveTimer, SIGNAL(timeout()), SLOT(checkMoved()) );
173
// LineEdit's size hint is to be vertically as small as possible
174
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
176
setWrapPolicy( AtWordOrDocumentBoundary ); // no need for horizontal scrollbar with this
177
setHScrollBarMode(QScrollView::AlwaysOff);
179
setMinimumHeight(-1);
181
connect( this, SIGNAL( textChanged() ), SLOT( recalculateSize() ) );
184
LineEdit::~LineEdit()
189
* Returns true if the dialog could be automatically resized by LineEdit.
191
bool LineEdit::allowResize() const
193
QWidget *topParent = topLevelWidget();
195
QRect desktop = qApp->desktop()->availableGeometry( (QWidget *)topParent );
196
float desktopArea = desktop.width() * desktop.height();
197
float dialogArea = topParent->frameGeometry().width() * topParent->frameGeometry().height();
199
// maximized and large chat windows shoulnd't resize the dialog
200
if ( (dialogArea / desktopArea) > 0.9 )
207
* In this implementation, it is quivalent to sizeHint().
209
QSize LineEdit::minimumSizeHint() const
215
* All magic is contained within this function. It determines the possible maximum
216
* height, and controls the appearance of vertical scrollbar.
218
QSize LineEdit::sizeHint() const
220
if ( lastSize.width() != 0 && lastSize.height() != 0 )
223
lastSize.setWidth( QTextEdit::sizeHint().width() );
226
if ( paragraphs() > 0 ) {
227
for ( int i = 0; i < paragraphs(); i++ ) {
228
h += paragraphRect( i ).height();
232
QWidget *topParent = topLevelWidget();
233
QRect desktop = qApp->desktop()->availableGeometry( (QWidget *)topParent );
234
int dh = h - height();
236
bool showScrollBar = false;
238
// check that our dialog's height doesn't exceed the desktop's
239
if ( allowResize() && (topParent->frameGeometry().height() + dh) >= desktop.height() ) {
240
// handles the case when the dialog could be resized,
241
// but lineedit wants to occupy too much space, so we should limit it
242
h = desktop.height() - ( topParent->frameGeometry().height() - height() );
243
showScrollBar = true;
245
else if ( !allowResize() && (h > topParent->geometry().height()/2) ) {
246
// handles the case when the dialog could not be resized(i.e. it's maximized).
247
// in this case we limit maximum height of lineedit to the half of dialog's
249
h = topParent->geometry().height() / 2;
250
showScrollBar = true;
253
// enable vertical scrollbar only when we're surely in need for it
254
QTextEdit *textEdit = (QTextEdit *)this;
256
textEdit->setVScrollBarMode( AlwaysOn );
258
textEdit->setVScrollBarMode( AlwaysOff );
260
lastSize.setHeight( h );
265
* Handles automatic dialog resize.
267
void LineEdit::recalculateSize()
269
if ( !isUpdatesEnabled() )
272
QSize oldSize = lastSize;
273
lastSize = QSize( 0, 0 ); // force sizeHint() to update
274
QSize newSize = sizeHint();
276
if ( QABS(newSize.height() - oldSize.height()) > 1 ) {
277
if ( allowResize() ) {
278
parentWidget()->layout()->setEnabled( false ); // try to reduce some flicker
280
QWidget *topParent = topLevelWidget();
281
int dh = newSize.height() - oldSize.height();
283
// if we're going to shrink dialog considerably, minimum
284
// size will prevent us from doing it. Activating main
285
// layout after resize will reset minimum sizes to sensible values
286
topParent->setMinimumSize( 10, 10 );
288
topParent->resize( topParent->width(),
289
topParent->height() + dh );
291
bool canMove = dh > 0;
292
int newy = topParent->y();
294
// try to move window to its old position
295
if ( movedWindow() && dh < 0 ) {
296
newy = initialWindowGeometry.y();
300
// check, if we need to move dialog upper
301
QRect desktop = qApp->desktop()->availableGeometry( (QWidget *)topParent );
302
if ( canMove && ( newy + topParent->frameGeometry().height() >= desktop.bottom() ) ) {
303
// initialize default window position
304
if ( !movedWindow() ) {
305
initialWindowGeometry = topParent->frameGeometry();
308
newy = QMAX(0, desktop.bottom() - topParent->frameGeometry().height());
311
if ( canMove && newy != topParent->y() ) {
312
topParent->move( topParent->x(), newy );
313
moveTo = topParent->pos();
316
parentWidget()->layout()->setEnabled( true );
319
// issue a layout update
320
parentWidget()->layout()->activate();
324
void LineEdit::resizeEvent( QResizeEvent *e )
326
// issue a re-layout, just in case
327
lastSize = QSize( 0, 0 ); // force sizeHint() to update
328
sizeHint(); // update the size hint, and cache the value
329
topLevelWidget()->layout()->activate();
331
PsiTextView::resizeEvent( e );
334
void LineEdit::setUpdatesEnabled( bool enable )
336
bool ue = isUpdatesEnabled();
337
ChatEdit::setUpdatesEnabled( enable );
343
bool LineEdit::eventFilter(QObject *watched, QEvent *e)
345
if ( !parentWidget()->layout()->isEnabled() )
346
return ChatEdit::eventFilter( watched, e );
348
if ( e->type() == QEvent::Reparent ) {
349
// In case of tabbed chats, dialog could be reparented to a higher-level dialog
350
// we need to get move events from it too. And unnecessary event filters
351
// are automatically cleaned up by Qt.
352
topLevelWidget()->installEventFilter( this );
354
else if ( e->type() == QEvent::Move ) {
355
QWidget *topParent = topLevelWidget();
356
if ( watched == topParent ) {
357
moveTimer->start( 100, true );
361
return ChatEdit::eventFilter( watched, e );
364
//! This function serves as a workaround for multiple move events, some of which
365
//! have incorrect coordinates (at least on KDE)
366
void LineEdit::checkMoved()
368
QWidget *topParent = topLevelWidget();
369
if ( QABS(moveTo.x() - topParent->x()) > 1 ||
370
QABS(moveTo.y() - topParent->y()) > 1 ) {
371
moveTo = topParent->pos();
372
initialWindowGeometry = QRect( 0, 0, 0, 0 );
376
bool LineEdit::movedWindow() const
378
return initialWindowGeometry.left() ||
379
initialWindowGeometry.top() ||
380
initialWindowGeometry.width() ||
381
initialWindowGeometry.height();