📄 qimpensetup.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qimpenwidget.h"#include "qimpenprefbase.h"#include "qimpensetup.h"#include <qtopia/qpeapplication.h>#include <qtopia/config.h>#include <qcombobox.h>#include <qlistbox.h>#include <qlabel.h>#include <qpushbutton.h>#include <qlayout.h>#include <qpixmap.h>#include <qbuttongroup.h>#include <qslider.h>#include <qtabwidget.h>#include <qdir.h>#include <qmessagebox.h>/* XPM */static const char * const left_xpm[] = {"16 16 2 1"," c None",". c #000000"," "," "," "," . "," .. "," ... "," .... "," ..... "," ...... "," ..... "," .... "," ... "," .. "," . "," "," "};/* XPM */static const char * const right_xpm[] = {"16 16 2 1"," c None",". c #000000"," "," "," "," . "," .. "," ... "," .... "," ..... "," ...... "," ..... "," .... "," ... "," .. "," . "," "," "};int QIMPenSetup::lastTab = 0;QIMPenSetup::QIMPenSetup( QIMPenProfile *p, QWidget *parent, const char *name, bool modal, int WFlags ) : QDialog( parent, name, modal, WFlags ), profileCombo(0), profile(p){ setCaption( tr("Setup Handwriting Input") ); QVBoxLayout *vb = new QVBoxLayout( this );#if 0 profileList.setAutoDelete( true ); QHBoxLayout *hb = new QHBoxLayout( vb ); hb->setMargin( 6 ); QLabel *l = new QLabel( tr("Character Profile:"), this ); hb->addWidget( l ); profileCombo = new QComboBox( this ); connect( profileCombo, SIGNAL(activated(const QString &)), this, SLOT(selectProfile(const QString &)) ); hb->addWidget( profileCombo ); loadProfiles();#else profileList.append( profile );#endif tabs = new QTabWidget( this ); vb->addWidget( tabs ); pref = new QIMPenPrefBase( this ); tabs->addTab( pref, tr("Preferences") ); pref->inputStyle->setExclusive( TRUE ); style = profile->style() == QIMPenProfile::ToggleCases ? 1 : 0; pref->inputStyle->setButton( style ); connect( pref->inputStyle, SIGNAL(clicked(int)), this, SLOT(styleClicked(int)) ); pref->inputStyle->setEnabled( profile->canSelectStyle() ); multiTimeout = profile->multiStrokeTimeout(); pref->multiStrokeSlider->setValue( multiTimeout ); multiTimeoutChanged( multiTimeout ); connect( pref->multiStrokeSlider, SIGNAL(valueChanged(int)), this, SLOT(multiTimeoutChanged(int)) ); edit = new QIMPenEdit( p, tabs ); tabs->addTab( edit, tr("Customize") ); tabs->setCurrentPage( lastTab );}QIMPenSetup::~QIMPenSetup(){ lastTab = tabs->currentPageIndex();}void QIMPenSetup::loadProfiles(){ QString path = QPEApplication::qpeDir() + "etc/qimpen"; QDir dir( path, "*.conf" ); QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QIMPenProfile *p = new QIMPenProfile( path + "/" + *it ); profileList.append( p ); profileCombo->insertItem( p->name() ); if ( p->name() == profile->name() ) { profileCombo->setCurrentItem( profileCombo->count()-1 ); profile = p; } }}void QIMPenSetup::styleClicked( int id ){ style = id;}void QIMPenSetup::multiTimeoutChanged( int v ){ multiTimeout = v; pref->multiStrokeLabel->setText( tr("%1 ms","milliseconds").arg(v) );}void QIMPenSetup::selectProfile( const QString &p ){ if ( p == profile->name() ) return; profile->setStyle( style ? QIMPenProfile::ToggleCases : QIMPenProfile::BothCases ); profile->setMultiStrokeTimeout( multiTimeout ); for ( int i = 0; i < (int)profileList.count(); i++ ) { if ( profileList.at(i)->name() == p ) { profile = profileList.at(i); style = profile->style() == QIMPenProfile::ToggleCases ? 1 : 0; pref->inputStyle->setButton( style ); pref->inputStyle->setEnabled( profile->canSelectStyle() ); multiTimeout = profile->multiStrokeTimeout(); pref->multiStrokeSlider->setValue( multiTimeout ); multiTimeoutChanged( multiTimeout ); edit->setProfile( profile ); break; } }}void QIMPenSetup::accept(){ profile->setStyle( style ? QIMPenProfile::ToggleCases : QIMPenProfile::BothCases ); profile->setMultiStrokeTimeout( multiTimeout ); // Save current profile if ( profileCombo ) { Config config( "handwriting" ); config.setGroup( "Settings" ); config.writeEntry( "Profile", profileCombo->currentText() ); } // Save charsets bool ok = TRUE; for ( int i = 0; i < (int)profileList.count(); i++ ) { QIMPenProfile *prof = profileList.at(i); QIMPenCharSetIterator it(prof->charSets()); for ( ; it.current(); ++it ) { if ( !(it.current()->save( QIMPenCharSet::User )) ) { ok = FALSE; break; } } } if ( !ok ) { if ( QMessageBox::critical( 0, tr( "Out of space" ), tr("Unable to save information.\n" "Free up some space\n" "and try again.\n" "\nQuit anyway?"), QMessageBox::Yes|QMessageBox::Escape, QMessageBox::No|QMessageBox::Default ) != QMessageBox::No ) { QDialog::accept(); } } else { QDialog::accept(); }}//---------------------------------------------------------------------------QIMPenInputCharDlg::QIMPenInputCharDlg( QWidget *parent, const char *name, bool modal, int WFlags) : QDialog( parent, name, modal, WFlags ){ setCaption( tr("Enter new character") ); uni = 0; QVBoxLayout *vb = new QVBoxLayout( this, 10 ); QHBoxLayout *hb = new QHBoxLayout(); vb->addLayout( hb ); QLabel *label = new QLabel( tr("Character:"), this ); hb->addWidget( label ); QComboBox *cb = new QComboBox( TRUE, this ); connect( cb, SIGNAL(activated(int)), SLOT(setSpecial(int)) ); connect( cb, SIGNAL(textChanged(const QString &)), SLOT(setCharacter(const QString &)) ); addSpecial( cb ); cb->setEditText( "" ); hb->addWidget( cb ); hb = new QHBoxLayout(); vb->addLayout( hb ); QPushButton *pb = new QPushButton( tr("OK"), this ); connect( pb, SIGNAL(clicked()), SLOT(accept())); hb->addWidget( pb ); pb = new QPushButton( tr("Cancel"), this ); connect( pb, SIGNAL(clicked()), SLOT(reject())); hb->addWidget( pb ); cb->setFocus();}void QIMPenInputCharDlg::addSpecial( QComboBox *cb ){ int i = 0; while ( qimpen_specialKeys[i].code != Key_unknown ) { cb->insertItem( qApp->translate("Handwriting",qimpen_specialKeys[i].name) ); i++; }}void QIMPenInputCharDlg::setSpecial( int sp ){ uni = qimpen_specialKeys[sp].code << 16;}void QIMPenInputCharDlg::setCharacter( const QString &string ){ uni = string[0].unicode();}//---------------------------------------------------------------------------class CharListItem : public QListBoxText{public: CharListItem( const QString &text, uint c ) : QListBoxText( text ) { _code = c; } uint code() const { return _code; }protected: uint _code;};int QIMPenEdit::lastCs = 1; // usually lowercaseint QIMPenEdit::lastCh = 0;/*! \class QIMPenEdit qimpensetup.h \brief The QIMPenEdit class allows character editing. Class to allow users to input totally useless character definitions which could match any number of the default set.*/QIMPenEdit::QIMPenEdit( QIMPenProfile *p, QWidget *parent, const char *name ) : QWidget( parent, name ), currentSet(0), profile(p){ currentChar = 0; currentCode = 0; inputChar = new QIMPenChar(); QVBoxLayout *tvb = new QVBoxLayout( this, 5 ); QGridLayout *gl = new QGridLayout( tvb, 4, 2 ); gl->setRowStretch( 1, 1 ); gl->addRowSpacing( 2, 35 ); gl->addRowSpacing( 3, 35 ); charSetCombo = new QComboBox( this ); gl->addMultiCellWidget( charSetCombo, 0, 0, 0, 1 ); connect( charSetCombo, SIGNAL(activated(int)), SLOT(selectCharSet(int))); QIMPenCharSetIterator it( profile->charSets() ); for ( ; it.current(); ++it ) { charSetCombo->insertItem( it.current()->description() ); } charList = new QListBox( this ); charList->setMinimumHeight( charList->sizeHint().height() ); connect( charList, SIGNAL(highlighted(int)), SLOT(selectChar(int)) ); gl->addWidget( charList, 1, 0 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -