Back to index

scribus-ng  1.3.4.dfsg+svn20071115
hyask.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "hyask.h"
00008 #include "hyask.moc"
00009 #include <qpixmap.h>
00010 #include <qregexp.h>
00011 extern QPixmap loadIcon(QString nam);
00012 
00013 WortEdit::WortEdit(QWidget* parent) : QLineEdit(parent)
00014 {
00015 }
00016 
00017 void WortEdit::keyPressEvent(QKeyEvent *k)
00018 {
00019        int p = cursorPosition();
00020        QChar cc = text()[p];
00021        if ((k->key() == Key_Left) || (k->key() == Key_Right))
00022               QLineEdit::keyPressEvent(k);
00023        if (k->key() == Key_Delete)
00024        {
00025               if (cc == "-")
00026                      QLineEdit::keyPressEvent(k);
00027               setCursorPosition(p);
00028        }
00029        if ((k->key() == Key_Backspace) && (p != 0))
00030        {
00031               cc = text()[p-1];
00032               if (cc == "-")
00033                      QLineEdit::keyPressEvent(k);
00034               setCursorPosition(p-1);
00035        }
00036        if (k->key() == Key_Minus)
00037               QLineEdit::keyPressEvent(k);
00038 }
00039 
00040 HyAsk::HyAsk( QWidget* parent, QString HWort )
00041     : QDialog( parent, "name", true, 0 )
00042 {
00043     resize( 322, 73 ); 
00044     setCaption( tr( "Possible Hyphenation" ) );
00045        setIcon(loadIcon("AppIcon.png"));
00046     HyAskLayout = new QVBoxLayout( this, 11, 6, "HyAskLayout"); 
00047 
00048     Wort = new WortEdit( this );
00049     Wort->setMinimumSize( QSize( 300, 0 ) );
00050     Wort->setDragEnabled( false );
00051     Wort->setText( HWort );
00052     HyAskLayout->addWidget( Wort );
00053 
00054     Layout1 = new QHBoxLayout( 0, 0, 6, "Layout1"); 
00055     QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00056     Layout1->addItem( spacer );
00057 
00058     OK = new QPushButton( this, "OK" );
00059     OK->setText( tr( "Accept" ) );
00060     OK->setDefault( true );
00061     Layout1->addWidget( OK );
00062     QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00063     Layout1->addItem( spacer_2 );
00064     Skip = new QPushButton( this, "cancel2" );
00065     Skip->setText( tr( "Skip" ) );
00066     Layout1->addWidget( Skip );
00067     QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00068     Layout1->addItem( spacer_3 );
00069     Cancel = new QPushButton( this, "cancel" );
00070     Cancel->setText( tr( "Cancel" ) );
00071     Layout1->addWidget( Cancel );
00072     QSpacerItem* spacer_4 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00073     Layout1->addItem( spacer_4 );
00074     HyAskLayout->addLayout( Layout1 );
00075        connect(OK, SIGNAL(clicked()), this, SLOT(accept()));
00076        connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
00077        connect(Skip, SIGNAL(clicked()), this, SLOT(DoSkip()));
00078        connect(Wort, SIGNAL(textChanged(const QString &)), this, SLOT(Check()));
00079 }
00080 
00081 void HyAsk::accept()
00082 {
00083        xpos = pos().x();
00084        ypos = pos().y();
00085        QDialog::accept();
00086 }
00087 
00088 void HyAsk::reject()
00089 {
00090        xpos = pos().x();
00091        ypos = pos().y();
00092        QDialog::reject();
00093 }
00094 
00095 void HyAsk::Check()
00096 {
00097        disconnect(Wort, SIGNAL(textChanged(const QString &)), this, SLOT(Check()));
00098        QString in = Wort->text();
00099        QString out = in.replace(QRegExp("(-)+"), "-");
00100        Wort->setText(out);
00101        connect(Wort, SIGNAL(textChanged(const QString &)), this, SLOT(Check()));
00102 }
00103 
00104 void HyAsk::DoSkip()
00105 {
00106        disconnect(Wort, SIGNAL(textChanged(const QString &)), this, SLOT(Check()));
00107        QString in = Wort->text();
00108        QString out = in.replace(QRegExp("(-)+"), "");
00109        Wort->setText(out);
00110        accept();
00111 }
00112