summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-19 19:47:13 (UTC)
committer mickeyl <mickeyl>2003-10-19 19:47:13 (UTC)
commitb96ee77f28d8d2e697528290204f15913c3f4c3e (patch) (side-by-side diff)
tree603b15d584bfcd9ee90b2e95a6852c028d7d5247
parent38d72acc2225b88b2f561fa59565d4c66261f1c3 (diff)
downloadopie-b96ee77f28d8d2e697528290204f15913c3f4c3e.zip
opie-b96ee77f28d8d2e697528290204f15913c3f4c3e.tar.gz
opie-b96ee77f28d8d2e697528290204f15913c3f4c3e.tar.bz2
This patch finish the work on the resizable inputmethods.
- in "floating" mode, input methods now remember their geometry - if closed via (x), the inputmethod button is toggled accordingly - eliminated the focus problem
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp76
-rw-r--r--core/launcher/inputmethods.h1
2 files changed, 69 insertions, 8 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
@@ -55,98 +55,98 @@
/* XPM */
static const char * tri_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
".........",
".........",
"....a....",
"...aaa...",
"..aaaaa..",
".aaaaaaa.",
".........",
"........."};
int InputMethod::operator <(const InputMethod& o) const
{
return name() < o.name();
}
int InputMethod::operator >(const InputMethod& o) const
{
return name() > o.name();
}
int InputMethod::operator <=(const InputMethod& o) const
{
return name() <= o.name();
}
/*
Slightly hacky: We use WStyle_Tool as a flag to say "this widget
belongs to the IM system, so clicking it should not cause a reset".
*/
class IMToolButton : public QToolButton
{
public:
IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent )
{ setWFlags( WStyle_Tool ); }
};
InputMethods::InputMethods( QWidget *parent ) :
QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ),
mkeyboard(0), imethod(0)
{
Config cfg( "Launcher" );
cfg.setGroup( "InputMethods" );
- inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader;
- inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : QWidget::WStyle_Tool;
+ inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool;
+ inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0;
inputWidgetWidth = cfg.readNumEntry( "Width", 100 );
setBackgroundMode( PaletteBackground );
QHBoxLayout *hbox = new QHBoxLayout( this );
kbdButton = new IMToolButton( this);
kbdButton->setFocusPolicy(NoFocus);
kbdButton->setToggleButton( TRUE );
if (parent->sizeHint().height() > 0)
kbdButton->setFixedHeight( parent->sizeHint().height() );
kbdButton->setFixedWidth( 32 );
kbdButton->setAutoRaise( TRUE );
kbdButton->setUsesBigPixmap( TRUE );
hbox->addWidget( kbdButton );
connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
kbdChoice = new IMToolButton( this );
kbdChoice->setFocusPolicy(NoFocus);
kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
if (parent->sizeHint().height() > 0)
kbdChoice->setFixedHeight( parent->sizeHint().height() );
kbdChoice->setFixedWidth( 13 );
kbdChoice->setAutoRaise( TRUE );
hbox->addWidget( kbdChoice );
connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
this, SLOT(resetStates()) );
imButton = new QWidgetStack( this ); // later a widget stack
imButton->setFocusPolicy(NoFocus);
if (parent->sizeHint().height() > 0)
imButton->setFixedHeight( parent->sizeHint().height() );
hbox->addWidget(imButton);
imChoice = new QToolButton( this );
imChoice->setFocusPolicy(NoFocus);
imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
if (parent->sizeHint().height() > 0)
imChoice->setFixedHeight( parent->sizeHint().height() );
imChoice->setFixedWidth( 13 );
imChoice->setAutoRaise( TRUE );
hbox->addWidget( imChoice );
connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) );
loadInputMethods();
@@ -487,80 +487,140 @@ void InputMethods::updateKeyboards(InputMethod *im )
kbdChoice->show();
else
kbdChoice->hide();
if ( count )
kbdButton->show();
else
kbdButton->hide();
}
void InputMethods::chooseMethod(InputMethod* im)
{
if ( im != imethod ) {
updateKeyboards( im );
Config cfg("qpe");
cfg.setGroup("InputMethod");
if (im )
cfg.writeEntry("im", im->name() );
if (mkeyboard)
cfg.writeEntry("current", mkeyboard->name() );
QWSServer::setCurrentInputMethod( 0 );
imethod = im;
if ( imethod && imethod->newIM )
QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
else
QWSServer::setCurrentInputMethod( 0 );
if ( im )
imButton->raiseWidget(im->widget);
else
imButton->hide(); //### good UI? make sure it is shown again!
}
}
void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data )
{
if ( imethod && imethod->newIM )
imethod->extInterface->qcopReceive( msg, data );
}
void InputMethods::showKbd( bool on )
{
if ( !mkeyboard )
return;
- if ( on ) {
+ if ( on )
+ {
mkeyboard->resetState();
- // HACK... Make the texteditor fit with all input methods
- // Input methods should also never use more than about 40% of the screen
+
int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 );
- mkeyboard->widget->resize( qApp->desktop()->width() * (inputWidgetWidth*0.01), height );
- mkeyboard->widget->move( 0, mapToGlobal( QPoint() ).y() - height );
+ int width = qApp->desktop()->width() * (inputWidgetWidth*0.01);
+ int left = 0;
+ int top = mapToGlobal( QPoint() ).y() - height;
+
+ if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
+ {
+ qDebug( "InputMethods: reading geometry." );
+ Config cfg( "Launcher" );
+ cfg.setGroup( "InputMethods" );
+ int l = cfg.readNumEntry( "absX", -1 );
+ int t = cfg.readNumEntry( "absY", -1 );
+ int w = cfg.readNumEntry( "absWidth", -1 );
+ int h = cfg.readNumEntry( "absHeight", -1 );
+
+ if ( l > -1 && t > -1 && w > -1 && h > -1 )
+ {
+ qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h );
+ left = l;
+ top = t;
+ width = w;
+ height = h;
+ }
+ else
+ {
+ qDebug( "InputMethods: config values are new or not ok." );
+ }
+ }
+ else
+ {
+ qDebug( "InputMethods: no floating selected." );
+ }
+ mkeyboard->widget->resize( width, height );
+ mkeyboard->widget->move( left, top );
mkeyboard->widget->show();
- } else {
+ mkeyboard->widget->installEventFilter( this );
+ }
+ else
+ {
+ if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
+ {
+ QPoint pos = mkeyboard->widget->pos();
+ QSize siz = mkeyboard->widget->size();
+ qDebug( "InputMethods: saving geometry." );
+ Config cfg( "Launcher" );
+ cfg.setGroup( "InputMethods" );
+ cfg.writeEntry( "absX", pos.x() );
+ cfg.writeEntry( "absY", pos.y() );
+ cfg.writeEntry( "absWidth", siz.width() );
+ cfg.writeEntry( "absHeight", siz.height() );
+ cfg.write();
mkeyboard->widget->hide();
+ mkeyboard->widget->removeEventFilter( this );
+ }
}
emit inputToggled( on );
}
bool InputMethods::shown() const
{
return mkeyboard && mkeyboard->widget->isVisible();
}
QString InputMethods::currentShown() const
{
return mkeyboard && mkeyboard->widget->isVisible()
? mkeyboard->name() : QString::null;
}
void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
{
#if defined(Q_WS_QWS)
QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
#endif
}
+
+bool InputMethods::eventFilter( QObject* o, QEvent* e )
+{
+ if ( e->type() == QEvent::Close )
+ {
+ ( (QCloseEvent*) e )->ignore();
+ showKbd( false );
+ kbdButton->setOn( false );
+ return true;
+ }
+ return false;
+}
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
@@ -28,85 +28,86 @@
#include <qvaluelist.h>
class QToolButton;
class QWidgetStack;
struct InputMethod
{
#ifndef QT_NO_COMPONENT
QLibrary *library;
#endif
QWidget *widget;
QString libName;
bool newIM;
union {
InputMethodInterface *interface;
ExtInputMethodInterface *extInterface;
};
inline void releaseInterface() {
newIM ? (void)extInterface->release() : (void)interface->release();
library->unload();
delete library; library = 0l;
}
inline QString name() const { return newIM ? extInterface->name() : interface->name(); }
inline QPixmap *icon() const { return newIM ? extInterface->icon() : interface->icon(); }
inline QUnknownInterface *iface() { return newIM ? (QUnknownInterface *)extInterface : (QUnknownInterface *)interface; }
inline void resetState() { if ( !newIM ) interface->resetState(); }
int operator <(const InputMethod& o) const;
int operator >(const InputMethod& o) const;
int operator <=(const InputMethod& o) const;
};
class InputMethods : public QWidget
{
Q_OBJECT
public:
InputMethods( QWidget * );
~InputMethods();
QRect inputRect() const;
bool shown() const;
QString currentShown() const; // name of interface
void showInputMethod(const QString& id);
void showInputMethod();
void hideInputMethod();
void unloadInputMethods();
void loadInputMethods();
+ virtual bool eventFilter( QObject *, QEvent * );
signals:
void inputToggled( bool on );
private slots:
void chooseKbd();
void chooseIm();
void showKbd( bool );
void resetStates();
void sendKey( ushort unicode, ushort scancode, ushort modifiers, bool, bool );
void qcopReceive( const QCString &msg, const QByteArray &data );
private:
void setPreferedHandlers();
/*static */QStringList plugins()const;
/*static */void installTranslator( const QString& );
void unloadMethod( QValueList<InputMethod>& );
void chooseMethod(InputMethod* im);
void chooseKeyboard(InputMethod* im);
void updateKeyboards(InputMethod *im);
private:
QToolButton *kbdButton;
QToolButton *kbdChoice;
QWidgetStack *imButton; // later will be widget stack
QToolButton *imChoice;
InputMethod *mkeyboard;
InputMethod *imethod;
QValueList<InputMethod> inputMethodList;
QValueList<InputMethod> inputModifierList;
int inputWidgetStyle;
int inputWidgetWidth;
};
#endif // __INPUT_METHODS_H__