-rw-r--r-- | core/launcher/inputmethods.cpp | 88 | ||||
-rw-r--r-- | core/launcher/inputmethods.h | 1 |
2 files changed, 75 insertions, 14 deletions
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp index d89a366..8f3e812 100644 --- a/core/launcher/inputmethods.cpp +++ b/core/launcher/inputmethods.cpp | |||
@@ -71,66 +71,66 @@ static const char * tri_xpm[]={ | |||
71 | int InputMethod::operator <(const InputMethod& o) const | 71 | int InputMethod::operator <(const InputMethod& o) const |
72 | { | 72 | { |
73 | return name() < o.name(); | 73 | return name() < o.name(); |
74 | } | 74 | } |
75 | int InputMethod::operator >(const InputMethod& o) const | 75 | int InputMethod::operator >(const InputMethod& o) const |
76 | { | 76 | { |
77 | return name() > o.name(); | 77 | return name() > o.name(); |
78 | } | 78 | } |
79 | int InputMethod::operator <=(const InputMethod& o) const | 79 | int InputMethod::operator <=(const InputMethod& o) const |
80 | { | 80 | { |
81 | return name() <= o.name(); | 81 | return name() <= o.name(); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | /* | 85 | /* |
86 | Slightly hacky: We use WStyle_Tool as a flag to say "this widget | 86 | Slightly hacky: We use WStyle_Tool as a flag to say "this widget |
87 | belongs to the IM system, so clicking it should not cause a reset". | 87 | belongs to the IM system, so clicking it should not cause a reset". |
88 | */ | 88 | */ |
89 | class IMToolButton : public QToolButton | 89 | class IMToolButton : public QToolButton |
90 | { | 90 | { |
91 | public: | 91 | public: |
92 | IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) | 92 | IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) |
93 | { setWFlags( WStyle_Tool ); } | 93 | { setWFlags( WStyle_Tool ); } |
94 | }; | 94 | }; |
95 | 95 | ||
96 | 96 | ||
97 | InputMethods::InputMethods( QWidget *parent ) : | 97 | InputMethods::InputMethods( QWidget *parent ) : |
98 | QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), | 98 | QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), |
99 | mkeyboard(0), imethod(0) | 99 | mkeyboard(0), imethod(0) |
100 | { | 100 | { |
101 | Config cfg( "Launcher" ); | 101 | Config cfg( "Launcher" ); |
102 | cfg.setGroup( "InputMethods" ); | 102 | cfg.setGroup( "InputMethods" ); |
103 | inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader; | 103 | inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; |
104 | inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : QWidget::WStyle_Tool; | 104 | inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; |
105 | inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); | 105 | inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); |
106 | 106 | ||
107 | setBackgroundMode( PaletteBackground ); | 107 | setBackgroundMode( PaletteBackground ); |
108 | QHBoxLayout *hbox = new QHBoxLayout( this ); | 108 | QHBoxLayout *hbox = new QHBoxLayout( this ); |
109 | 109 | ||
110 | kbdButton = new IMToolButton( this); | 110 | kbdButton = new IMToolButton( this); |
111 | kbdButton->setFocusPolicy(NoFocus); | 111 | kbdButton->setFocusPolicy(NoFocus); |
112 | kbdButton->setToggleButton( TRUE ); | 112 | kbdButton->setToggleButton( TRUE ); |
113 | if (parent->sizeHint().height() > 0) | 113 | if (parent->sizeHint().height() > 0) |
114 | kbdButton->setFixedHeight( parent->sizeHint().height() ); | 114 | kbdButton->setFixedHeight( parent->sizeHint().height() ); |
115 | kbdButton->setFixedWidth( 32 ); | 115 | kbdButton->setFixedWidth( 32 ); |
116 | kbdButton->setAutoRaise( TRUE ); | 116 | kbdButton->setAutoRaise( TRUE ); |
117 | kbdButton->setUsesBigPixmap( TRUE ); | 117 | kbdButton->setUsesBigPixmap( TRUE ); |
118 | hbox->addWidget( kbdButton ); | 118 | hbox->addWidget( kbdButton ); |
119 | connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); | 119 | connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); |
120 | 120 | ||
121 | kbdChoice = new IMToolButton( this ); | 121 | kbdChoice = new IMToolButton( this ); |
122 | kbdChoice->setFocusPolicy(NoFocus); | 122 | kbdChoice->setFocusPolicy(NoFocus); |
123 | kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); | 123 | kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); |
124 | if (parent->sizeHint().height() > 0) | 124 | if (parent->sizeHint().height() > 0) |
125 | kbdChoice->setFixedHeight( parent->sizeHint().height() ); | 125 | kbdChoice->setFixedHeight( parent->sizeHint().height() ); |
126 | kbdChoice->setFixedWidth( 13 ); | 126 | kbdChoice->setFixedWidth( 13 ); |
127 | kbdChoice->setAutoRaise( TRUE ); | 127 | kbdChoice->setAutoRaise( TRUE ); |
128 | hbox->addWidget( kbdChoice ); | 128 | hbox->addWidget( kbdChoice ); |
129 | connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); | 129 | connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); |
130 | 130 | ||
131 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), | 131 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), |
132 | this, SLOT(resetStates()) ); | 132 | this, SLOT(resetStates()) ); |
133 | 133 | ||
134 | 134 | ||
135 | imButton = new QWidgetStack( this ); // later a widget stack | 135 | imButton = new QWidgetStack( this ); // later a widget stack |
136 | imButton->setFocusPolicy(NoFocus); | 136 | imButton->setFocusPolicy(NoFocus); |
@@ -501,66 +501,126 @@ void InputMethods::chooseMethod(InputMethod* im) | |||
501 | 501 | ||
502 | Config cfg("qpe"); | 502 | Config cfg("qpe"); |
503 | cfg.setGroup("InputMethod"); | 503 | cfg.setGroup("InputMethod"); |
504 | if (im ) | 504 | if (im ) |
505 | cfg.writeEntry("im", im->name() ); | 505 | cfg.writeEntry("im", im->name() ); |
506 | if (mkeyboard) | 506 | if (mkeyboard) |
507 | cfg.writeEntry("current", mkeyboard->name() ); | 507 | cfg.writeEntry("current", mkeyboard->name() ); |
508 | 508 | ||
509 | QWSServer::setCurrentInputMethod( 0 ); | 509 | QWSServer::setCurrentInputMethod( 0 ); |
510 | imethod = im; | 510 | imethod = im; |
511 | if ( imethod && imethod->newIM ) | 511 | if ( imethod && imethod->newIM ) |
512 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); | 512 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); |
513 | else | 513 | else |
514 | QWSServer::setCurrentInputMethod( 0 ); | 514 | QWSServer::setCurrentInputMethod( 0 ); |
515 | 515 | ||
516 | if ( im ) | 516 | if ( im ) |
517 | imButton->raiseWidget(im->widget); | 517 | imButton->raiseWidget(im->widget); |
518 | else | 518 | else |
519 | imButton->hide(); //### good UI? make sure it is shown again! | 519 | imButton->hide(); //### good UI? make sure it is shown again! |
520 | } | 520 | } |
521 | } | 521 | } |
522 | 522 | ||
523 | void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) | 523 | void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) |
524 | { | 524 | { |
525 | if ( imethod && imethod->newIM ) | 525 | if ( imethod && imethod->newIM ) |
526 | imethod->extInterface->qcopReceive( msg, data ); | 526 | imethod->extInterface->qcopReceive( msg, data ); |
527 | } | 527 | } |
528 | 528 | ||
529 | 529 | ||
530 | void InputMethods::showKbd( bool on ) | 530 | void InputMethods::showKbd( bool on ) |
531 | { | 531 | { |
532 | if ( !mkeyboard ) | 532 | if ( !mkeyboard ) |
533 | return; | 533 | return; |
534 | 534 | ||
535 | if ( on ) { | 535 | if ( on ) |
536 | mkeyboard->resetState(); | 536 | { |
537 | // HACK... Make the texteditor fit with all input methods | 537 | mkeyboard->resetState(); |
538 | // Input methods should also never use more than about 40% of the screen | 538 | |
539 | int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); | 539 | int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); |
540 | mkeyboard->widget->resize( qApp->desktop()->width() * (inputWidgetWidth*0.01), height ); | 540 | int width = qApp->desktop()->width() * (inputWidgetWidth*0.01); |
541 | mkeyboard->widget->move( 0, mapToGlobal( QPoint() ).y() - height ); | 541 | int left = 0; |
542 | mkeyboard->widget->show(); | 542 | int top = mapToGlobal( QPoint() ).y() - height; |
543 | } else { | 543 | |
544 | mkeyboard->widget->hide(); | 544 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) |
545 | { | ||
546 | qDebug( "InputMethods: reading geometry." ); | ||
547 | Config cfg( "Launcher" ); | ||
548 | cfg.setGroup( "InputMethods" ); | ||
549 | int l = cfg.readNumEntry( "absX", -1 ); | ||
550 | int t = cfg.readNumEntry( "absY", -1 ); | ||
551 | int w = cfg.readNumEntry( "absWidth", -1 ); | ||
552 | int h = cfg.readNumEntry( "absHeight", -1 ); | ||
553 | |||
554 | if ( l > -1 && t > -1 && w > -1 && h > -1 ) | ||
555 | { | ||
556 | qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h ); | ||
557 | left = l; | ||
558 | top = t; | ||
559 | width = w; | ||
560 | height = h; | ||
561 | } | ||
562 | else | ||
563 | { | ||
564 | qDebug( "InputMethods: config values are new or not ok." ); | ||
565 | } | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | qDebug( "InputMethods: no floating selected." ); | ||
570 | } | ||
571 | mkeyboard->widget->resize( width, height ); | ||
572 | mkeyboard->widget->move( left, top ); | ||
573 | mkeyboard->widget->show(); | ||
574 | mkeyboard->widget->installEventFilter( this ); | ||
575 | } | ||
576 | else | ||
577 | { | ||
578 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) | ||
579 | { | ||
580 | QPoint pos = mkeyboard->widget->pos(); | ||
581 | QSize siz = mkeyboard->widget->size(); | ||
582 | qDebug( "InputMethods: saving geometry." ); | ||
583 | Config cfg( "Launcher" ); | ||
584 | cfg.setGroup( "InputMethods" ); | ||
585 | cfg.writeEntry( "absX", pos.x() ); | ||
586 | cfg.writeEntry( "absY", pos.y() ); | ||
587 | cfg.writeEntry( "absWidth", siz.width() ); | ||
588 | cfg.writeEntry( "absHeight", siz.height() ); | ||
589 | cfg.write(); | ||
590 | mkeyboard->widget->hide(); | ||
591 | mkeyboard->widget->removeEventFilter( this ); | ||
592 | } | ||
545 | } | 593 | } |
546 | 594 | ||
547 | emit inputToggled( on ); | 595 | emit inputToggled( on ); |
548 | } | 596 | } |
549 | 597 | ||
550 | bool InputMethods::shown() const | 598 | bool InputMethods::shown() const |
551 | { | 599 | { |
552 | return mkeyboard && mkeyboard->widget->isVisible(); | 600 | return mkeyboard && mkeyboard->widget->isVisible(); |
553 | } | 601 | } |
554 | 602 | ||
555 | QString InputMethods::currentShown() const | 603 | QString InputMethods::currentShown() const |
556 | { | 604 | { |
557 | return mkeyboard && mkeyboard->widget->isVisible() | 605 | return mkeyboard && mkeyboard->widget->isVisible() |
558 | ? mkeyboard->name() : QString::null; | 606 | ? mkeyboard->name() : QString::null; |
559 | } | 607 | } |
560 | 608 | ||
561 | void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) | 609 | void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) |
562 | { | 610 | { |
563 | #if defined(Q_WS_QWS) | 611 | #if defined(Q_WS_QWS) |
564 | QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); | 612 | QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); |
565 | #endif | 613 | #endif |
566 | } | 614 | } |
615 | |||
616 | bool InputMethods::eventFilter( QObject* o, QEvent* e ) | ||
617 | { | ||
618 | if ( e->type() == QEvent::Close ) | ||
619 | { | ||
620 | ( (QCloseEvent*) e )->ignore(); | ||
621 | showKbd( false ); | ||
622 | kbdButton->setOn( false ); | ||
623 | return true; | ||
624 | } | ||
625 | return false; | ||
626 | } | ||
diff --git a/core/launcher/inputmethods.h b/core/launcher/inputmethods.h index 246661a..55ac020 100644 --- a/core/launcher/inputmethods.h +++ b/core/launcher/inputmethods.h | |||
@@ -44,64 +44,65 @@ struct InputMethod | |||
44 | }; | 44 | }; |
45 | 45 | ||
46 | inline void releaseInterface() { | 46 | inline void releaseInterface() { |
47 | newIM ? (void)extInterface->release() : (void)interface->release(); | 47 | newIM ? (void)extInterface->release() : (void)interface->release(); |
48 | library->unload(); | 48 | library->unload(); |
49 | delete library; library = 0l; | 49 | delete library; library = 0l; |
50 | } | 50 | } |
51 | inline QString name() const { return newIM ? extInterface->name() : interface->name(); } | 51 | inline QString name() const { return newIM ? extInterface->name() : interface->name(); } |
52 | inline QPixmap *icon() const { return newIM ? extInterface->icon() : interface->icon(); } | 52 | inline QPixmap *icon() const { return newIM ? extInterface->icon() : interface->icon(); } |
53 | inline QUnknownInterface *iface() { return newIM ? (QUnknownInterface *)extInterface : (QUnknownInterface *)interface; } | 53 | inline QUnknownInterface *iface() { return newIM ? (QUnknownInterface *)extInterface : (QUnknownInterface *)interface; } |
54 | inline void resetState() { if ( !newIM ) interface->resetState(); } | 54 | inline void resetState() { if ( !newIM ) interface->resetState(); } |
55 | 55 | ||
56 | int operator <(const InputMethod& o) const; | 56 | int operator <(const InputMethod& o) const; |
57 | int operator >(const InputMethod& o) const; | 57 | int operator >(const InputMethod& o) const; |
58 | int operator <=(const InputMethod& o) const; | 58 | int operator <=(const InputMethod& o) const; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | class InputMethods : public QWidget | 61 | class InputMethods : public QWidget |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | InputMethods( QWidget * ); | 65 | InputMethods( QWidget * ); |
66 | ~InputMethods(); | 66 | ~InputMethods(); |
67 | 67 | ||
68 | QRect inputRect() const; | 68 | QRect inputRect() const; |
69 | bool shown() const; | 69 | bool shown() const; |
70 | QString currentShown() const; // name of interface | 70 | QString currentShown() const; // name of interface |
71 | void showInputMethod(const QString& id); | 71 | void showInputMethod(const QString& id); |
72 | void showInputMethod(); | 72 | void showInputMethod(); |
73 | void hideInputMethod(); | 73 | void hideInputMethod(); |
74 | void unloadInputMethods(); | 74 | void unloadInputMethods(); |
75 | void loadInputMethods(); | 75 | void loadInputMethods(); |
76 | virtual bool eventFilter( QObject *, QEvent * ); | ||
76 | 77 | ||
77 | signals: | 78 | signals: |
78 | void inputToggled( bool on ); | 79 | void inputToggled( bool on ); |
79 | 80 | ||
80 | private slots: | 81 | private slots: |
81 | void chooseKbd(); | 82 | void chooseKbd(); |
82 | void chooseIm(); | 83 | void chooseIm(); |
83 | void showKbd( bool ); | 84 | void showKbd( bool ); |
84 | void resetStates(); | 85 | void resetStates(); |
85 | void sendKey( ushort unicode, ushort scancode, ushort modifiers, bool, bool ); | 86 | void sendKey( ushort unicode, ushort scancode, ushort modifiers, bool, bool ); |
86 | void qcopReceive( const QCString &msg, const QByteArray &data ); | 87 | void qcopReceive( const QCString &msg, const QByteArray &data ); |
87 | 88 | ||
88 | private: | 89 | private: |
89 | void setPreferedHandlers(); | 90 | void setPreferedHandlers(); |
90 | /*static */QStringList plugins()const; | 91 | /*static */QStringList plugins()const; |
91 | /*static */void installTranslator( const QString& ); | 92 | /*static */void installTranslator( const QString& ); |
92 | void unloadMethod( QValueList<InputMethod>& ); | 93 | void unloadMethod( QValueList<InputMethod>& ); |
93 | void chooseMethod(InputMethod* im); | 94 | void chooseMethod(InputMethod* im); |
94 | void chooseKeyboard(InputMethod* im); | 95 | void chooseKeyboard(InputMethod* im); |
95 | void updateKeyboards(InputMethod *im); | 96 | void updateKeyboards(InputMethod *im); |
96 | 97 | ||
97 | private: | 98 | private: |
98 | QToolButton *kbdButton; | 99 | QToolButton *kbdButton; |
99 | QToolButton *kbdChoice; | 100 | QToolButton *kbdChoice; |
100 | QWidgetStack *imButton; // later will be widget stack | 101 | QWidgetStack *imButton; // later will be widget stack |
101 | QToolButton *imChoice; | 102 | QToolButton *imChoice; |
102 | InputMethod *mkeyboard; | 103 | InputMethod *mkeyboard; |
103 | InputMethod *imethod; | 104 | InputMethod *imethod; |
104 | QValueList<InputMethod> inputMethodList; | 105 | QValueList<InputMethod> inputMethodList; |
105 | QValueList<InputMethod> inputModifierList; | 106 | QValueList<InputMethod> inputModifierList; |
106 | int inputWidgetStyle; | 107 | int inputWidgetStyle; |
107 | int inputWidgetWidth; | 108 | int inputWidgetWidth; |