25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
krename/krename/coorddialog.cpp

143 satır
4.8 KiB

/***************************************************************************
coorddialog.cpp - description
-------------------
begin : Die Feb 4 2003
copyright : (C) 2003 by Dominik Seichter
email : domseichter@web.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "coorddialog.h"
// TQt includes
#include <tqcheckbox.h>
#include <tqfontmetrics.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqvalidator.h>
// KDE includes
#include <kapplication.h>
#include <klocale.h>
DSLineEdit::DSLineEdit( TQWidget* tqparent, const char* name )
: KLineEdit( tqparent, name )
{
}
void DSLineEdit::keyPressEvent( TQKeyEvent* e )
{
KLineEdit::keyPressEvent( e );
emit changed();
}
void DSLineEdit::mousePressEvent( TQMouseEvent* e )
{
KLineEdit::mousePressEvent( e );
emit changed();
}
bool CoordDialog::m_inversion = false;
CoordDialog::CoordDialog( const TQString & file, TQWidget *_parent, const char *name )
: KDialogBase( KDialogBase::Plain, "KRename",
KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, _parent, name, true, true ), m_file( file )
{
TQFrame* tqparent = plainPage();
TQVBoxLayout* tqlayout = new TQVBoxLayout( tqparent );
filename = new DSLineEdit( tqparent );
filename->setText( file );
filename->setValidator( new TQRegExpValidator( TQRegExp( file ), TQT_TQOBJECT(this) ) );
preview = new TQLabel( tqparent );
checkInvert = new TQCheckBox( i18n("&Invert selection"), plainPage() );
checkInvert->setChecked( m_inversion );
tqlayout->addWidget( new TQLabel( i18n("Please select the text you want to insert:"), plainPage() ) );
tqlayout->addWidget( filename );
tqlayout->addWidget( checkInvert );
tqlayout->addWidget( preview );
updateCommand();
connect( filename, TQT_SIGNAL( selectionChanged() ), this, TQT_SLOT( updateCommand() ) );
connect( checkInvert, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updateCommand() ) );
connect( filename, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( resetText() ) );
connect( filename, TQT_SIGNAL( changed() ), this, TQT_SLOT( updateCommand() ) );
show();
TQFontMetrics fm( filename->font() );
int w = fm.width( file );
if( w > width() )
resize(
( w < KApplication::desktop()->width() - 40 ? w + 40 : KApplication::desktop()->width() ), height() );
}
CoordDialog::~CoordDialog()
{
}
void CoordDialog::updateCommand()
{
int start = 0;
int end = 0;
m_command = "";
(void)filename->getSelection( &start, &end );
if( !filename->text().isEmpty() ) {
if( checkInvert->isChecked() && filename->hasSelectedText() ) {
// inverted
if( end ) {
start++;
end++;
if( start > 1 )
m_command = TQString("[$1;%1]").tqarg(start-1);
if( end <= (signed int)filename->text().length() )
m_command.append( TQString("[$%1-[length]]").tqarg(end) );
}
} else if( checkInvert->isChecked() && !filename->hasSelectedText() ) {
int p = filename->cursorPosition();
m_command = TQString("[$1;%1][$%2-[length]]").tqarg(p).tqarg(p+1);
} else if( !checkInvert->isChecked() && filename->hasSelectedText() ){
if( end ) {
start++;
end++;
if( end <= (signed int)filename->text().length() )
m_command = TQString("[$%1;%2]").tqarg(start).tqarg(end-start);
else
m_command = TQString("[$%1-[length]]").tqarg(start);
}
} else if( !checkInvert->isChecked() && !filename->hasSelectedText() ) {
int p = filename->cursorPosition();
m_command = TQString("[$%1-[length]]").tqarg( p );
}
}
preview->setText( i18n("Preview: ") + m_command );
}
void CoordDialog::resetText()
{
filename->setText( m_file );
updateCommand();
}
TQString CoordDialog::coords()
{
m_inversion = checkInvert->isChecked();
return m_command;
}