📄 qdl.cpp
字号:
delete d->lc; d->lc = 0; d->timer->stop();}/*! \internal Generates a new link identifier*/uint QDLClient::nextLID(){ uint numLids = d->links.count(); for( uint i = 1 ; i <= numLids ; ++i ) if( !(d->links.contains( i )) ) return i; return numLids+1;} #include <qlineedit.h>#include <qmultilineedit.h>//add more widgets hereunion QDLClientWidgets{ QLineEdit *le; QMultiLineEdit *me; //add more widgets here};class QDLWidgetClientPrivate{public: QDLClientWidgets widget; QString widgetType;};/*! \class QDLWidgetClient qdl.h \brief The QDLWidgetClient class is a QDLClient that interfaces with a widget. A QDLWidgetClient has all the capabilities of a QDLClient, but also depends on a widget and interfaces with its text. A QDLWidgetClient can currently interface with the following widgets. <ul> <li>QLineEdit <li>QMultiLineEdit </ul> Other widgets may be supported in later releases of Qtopia. \ingroup qtopiaemb*//*! Constructs a QDLWidgetClient with \a w as the parent and the monitored widget. \a name is passed on to QObject.*/QDLWidgetClient::QDLWidgetClient( QWidget *w, const char *name ) : QDLClient( w, name ){ d = new QDLWidgetClientPrivate(); setWidget( w );}/*! \internal Sets the widget for this client to \a w.*/void QDLWidgetClient::setWidget( QWidget *w ){ if( !w ) setWidgetType( QString::null ); else if( w->inherits( "QLineEdit" ) ) { d->widget.le = (QLineEdit *)w; setWidgetType( "QLineEdit" ); } else if( w->inherits( "QMultiLineEdit" ) ) { d->widget.me = (QMultiLineEdit *)w; setWidgetType( "QMultiLineEdit" ); } //add more widgets here}/*! \internal Returns the widget for this client. Returns 0 if an unsupported widget was passed to the constructor. \sa QDLWidgetClient::QDLWidgetClient()*/QWidget *QDLWidgetClient::widget() const{ QString wt = widgetType(); if( wt == "QLineEdit" ) return d->widget.le; else if( wt == "QMultiLineEdit" ) return d->widget.me; //add more widgets here else return 0;}/*! \internal Sets the type of the widget for the client to \a t. The type is the class name of the widget, eg QLineEdit*/void QDLWidgetClient::setWidgetType( const QString &t ){ d->widgetType = t;}/*! \internal Returns the type of the widget for the client.*/QString QDLWidgetClient::widgetType() const{ return d->widgetType;}/*! Returns the text of the client's widget.*/QString QDLWidgetClient::text() const{ QString wt = widgetType(); if( wt == "QLineEdit" ) return d->widget.le->text(); else if( wt == "QMultiLineEdit" ) return d->widget.me->text(); //add more widgets here else return QString::null;}/*! Adds \a newLink to the client. A new link identifier is generated. The link is also added into the widget's text.*/void QDLWidgetClient::addLink( const QDLLink &newLink ){ uint nl = nextLID(); int p = textPos(); QString t = text(); QString space; if( !t.isEmpty() && p ) if( !t[p-1].isSpace() ) space = " "; t = t.insert( p, space+newLink.description()+QDL::lidFromUInt(nl) ); setText( t ); QDLClient::setLink( nl, newLink );}/*! Sets the link specified by the link identifier \a lid to \a newLink both in QDLClient and in the widget's text. If no link for \a lid currently exists, it is created and added to the widget's text.*/void QDLWidgetClient::setLink( uint lid, const QDLLink &newLink ){ QDLLink l = link( lid ); QString t = text(); //first try and find the description and lid. failing that, just the lid QString lt = l.description()+QDL::lidFromUInt(lid); int f = t.find( lt ); if( f != -1 ) { t = t.remove( f, lt.length() ); } else { QString textLID = QDL::lidFromUInt(lid); f = t.find( textLID ); if( f != -1 ) { t = t.remove( f, textLID.length() ); } else { f = 0; } } t = t.insert( f, newLink.description()+lid ); setText( t ); QDLClient::setLink( lid, newLink );}/*! Removes the link specified by the link identifier \a lid. It is removed from QDLClient and in the widget's text.*/void QDLWidgetClient::removeLink( uint lid ){ if( links().contains( lid ) ) { QDLLink l = link( lid ); QString lt = l.description()+QDL::lidFromUInt(lid); //first try and find the description and lid. failing that, just the lid QString t = text(); int f = t.find( lt ); if( f != -1 ) { t = t.remove( f, lt.length() ); setText( t ); } else { QString textLID = QDL::lidFromUInt( lid ); f = t.find( textLID ); if( f != -1 ) { t = t.remove( f, textLID.length() ); } setText( t ); } QDLClient::removeLink( lid ); }}#ifdef QTOPIA_PHONE /*! Automatically creates a standard 'Insert Link' action in the ContextMenu specified by \a context. If \a context is 0, a new ContextMenu is created. The action is connected to QDLWidgetClient::requestLink().*/ContextMenu *QDLWidgetClient::setupStandardContextMenu( ContextMenu *context )// TODO : How does this work on the PDA?{ QWidget *w = widget(); if( !w ) { qWarning("BUG : trying to setup a context menu on a null widget client"); return 0; } if ( !context ) context = new ContextMenu( w, 0, ContextMenu::Modal ); QAction *action = new QAction( tr( "Insert Link" ), Resource::loadIconSet( "qdllink" ), QString::null, 0, w, 0 ); QObject::connect( action, SIGNAL(activated()), this, SLOT(requestLink()) ); action->addTo( context ); context->insertItem(Resource::loadIconSet("cut"), tr("Cut"), w, SLOT(cut())); context->insertItem(Resource::loadIconSet("copy"), tr("Copy"), w, SLOT(copy())); context->insertItem(Resource::loadIconSet("paste"), tr("Paste"), w, SLOT(paste())); return context;}#endif/*! \internal Sets the text of the widget to \a txt.*/void QDLWidgetClient::setText( const QString &txt ){ QWidget *w = widget(); if( !w ) return; w->setFocus();#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) { if( w->isModalEditing() ) w->setModalEditing( TRUE ); }#endif QString wt = widgetType(); if( wt == "QLineEdit" ) d->widget.le->setText( txt ); else if( wt == "QMultiLineEdit" ) d->widget.me->setText( txt ); //add more widgets here}/*! Convenience function. Simply calls QDLClient::requestLink() with the client's widget as parent.*/void QDLWidgetClient::requestLink(){ QDLClient::requestLink( widget() );}/*! Returns the request hint for this widget. If a hint has not been explicitly set with QDLClient::setHint(), then this function tries to dynamically determine the hint from the text of the client's widget, otherwise it just returns QDLClient::hint() */QString QDLWidgetClient::hint() const{ //if the user has manually set a hint use that otherwise determine a hint(selection) QString h = QDLClient::hint(); if( !h.isEmpty() ) return h; return determineHint();}/*! \internal Dynamically determines a hint from the widget's text. This is currently the selected text of the widget, and therefore doesn't work on Qtopia Phone Edition.*/QString QDLWidgetClient::determineHint() const{ QString wt = widgetType(); if( wt == "QLineEdit" ) return d->widget.le->markedText(); else if( wt == "QMultiLineEdit" ) /*FIXME return d->widget.me->markedText()*/; //add more widgets here return QString::null;}/*! \internal Returns the current position within text() (eg cursor position)*/int QDLWidgetClient::textPos() const{ QString type = widgetType(); if( type == "QLineEdit" ) { return d->widget.le->cursorPosition(); } else if( type == "QMultiLineEdit" ) { QString t = text(); const int len = t.length(); int i = 0; int r = 0, c = 0; int rr = 0, rc = 0; //work out how many characters there are up to row,col d->widget.me->getCursorPosition( &rr, &rc ); while( i < len ) { if( t[i] == '\n' ) { ++r; c = 0; } else { ++c; } ++i; if( r == rr && c == rc ) break; } return i; } //add more widgets here return 0;}/*! Verifies that all internal links of QDLClient exist in the widget's text. Any internal link that doesn't exist in the widget's text is removed.*/void QDLWidgetClient::verifyLinks(){ QValueList<uint> invalidLids; QMap<uint, QDLLink>::ConstIterator it; QMap<uint, QDLLink> lnks = links(); for( it = lnks.begin() ; it != lnks.end() ; ++it ) { QString t = text(); int p = t.find( QDL::lidFromUInt(it.key()) ); if( p == -1 ) invalidLids.append( it.key() ); } QValueList<uint>::ConstIterator iit; for( iit = invalidLids.begin() ; iit != invalidLids.end() ; ++iit ) QDLClient::removeLink( *iit );}class QDLSourceSelectorApp{public: QDLSourceSelectorApp() { } QDLSourceSelectorApp( const QDLSourceSelectorApp &c ) { name = c.name; channel = c.channel; icon = c.icon; } QDLSourceSelectorApp( QString n, QString c, QPixmap i ) : name( n ), channel( c ), icon( i ) { name = Qtopia::dehyphenate(name); } QDLSourceSelectorApp &operator=( const QDLSourceSelectorApp &c ) { name = c.name; channel = c.channel; icon = c.icon; return *this; } QString name, channel; QPixmap icon;};class QDLSourceSelectorPrivate{public: QDLSourceSelectorPrivate() : appList( 0 ) { } QListBox *appList; QValueList<QDLSourceSelectorApp> apps; QMap<QListBoxItem *, int> itemToAppIndex;};QDLSourceSelector::QDLSourceSelector( QWidget *parent, const char *name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ){ d = new QDLSourceSelectorPrivate(); QVBoxLayout *l = new QVBoxLayout( this ); d->appList = new QListBox( this, "appList" ); l->addWidget( d->appList ); d->appList->setFocus(); setCaption( tr("Select Source") ); //get all applications that are qdl sources QStringList qdlApps = Service::apps( "qdl" ); if( qdlApps.count() ) { QStringList::Iterator it = qdlApps.begin(); AppLnkSet alList( QPEApplication::qpeDir() + "apps" ); for( ; it != qdlApps.end() ; ++it ) { AppLnk l = *alList.findExec( *it ); if( !l.isValid() ) { qWarning("QDLSourceSelector: Can't get a valid AppLnk for '%s'", (*it).latin1()); } else { QIconSet is( Resource::loadPixmap( l.icon() ) ); QDLSourceSelectorApp a( l.name(), "QPE/Application/" + (*it), is.pixmap( QIconSet::Small, TRUE ) ); d->apps.append( a ); } } } QValueList<QDLSourceSelectorApp> &a = d->apps; const int len = a.count(); for( int i = 0 ; i < len ; ++i ) { d->appList->insertItem( a[i].icon, a[i].name, i ); d->itemToAppIndex[ d->appList->item( i ) ] = i; } connect( d->appList, SIGNAL(selected(int)), this, SLOT(accept()) ); // and, since we are MenuLike... connect( d->appList, SIGNAL(clicked(QListBoxItem*)), this, SLOT(accept()) ); d->appList->sort(); if ( len && !d->appList->isSelected( d->appList->currentItem() ) ) // XXX should use most-recent-for-this-app d->appList->setSelected( 0, TRUE ); QPEApplication::setMenuLike( this, TRUE );}QMap<QString, QString> QDLSourceSelector::selected() const{ QListBox *l = d->appList; QMap<QString, QString> selections; const unsigned int numApps = l->count(); for( int i = 0 ; i < (int)numApps ; ++i ) { if( l->isSelected( i ) ) { int j = d->itemToAppIndex[l->item( i )]; selections[d->apps[j].name] = d->apps[j].channel; } } return selections;}QSize QDLSourceSelector::sizeHint() const{ return QSize( width(), qApp->desktop()->height() );}void QDLSourceSelector::accept(){ QDialog::accept(); emit selected( selected() );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -