KRename – powerful batch renamer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

numberdialog.cpp 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /***************************************************************************
  2. numberdialog.cpp - description
  3. -------------------
  4. begin : Don Apr 24 2003
  5. copyright : (C) 2003 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "numberdialog.h"
  17. #include "batchrenamer.h"
  18. // TQt includes
  19. #include <tqgroupbox.h>
  20. #include <tqlayout.h>
  21. #include <tqtooltip.h>
  22. // KDE includes
  23. #include <tdeapplication.h>
  24. #include <tdeconfig.h>
  25. #include <tdelocale.h>
  26. #include <kpushbutton.h>
  27. #include <tqcheckbox.h>
  28. void KMyIntSpinBox::keyPressEvent( TQKeyEvent* e )
  29. {
  30. if( e->key() == Key_Return )
  31. emit returnPressed();
  32. }
  33. NumberDialog::NumberDialog(TQValueList<int> & n,TQWidget *parent )
  34. : KDialogBase( KDialogBase::Plain, "KRename",
  35. KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent, 0, true, true )
  36. {
  37. TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  38. TQVBoxLayout* layout = new TQVBoxLayout( plainPage(), 6, 6 );
  39. TQGroupBox* group1 = new TQGroupBox( plainPage() );
  40. group1->setTitle( i18n("&Numbering") );
  41. group1->setColumnLayout(0, Qt::Vertical );
  42. group1->layout()->setSpacing( 6 );
  43. group1->layout()->setMargin( 11 );
  44. TQVBoxLayout* group1Layout = new TQVBoxLayout( group1->layout() );
  45. group1Layout->setAlignment( TQt::AlignTop );
  46. spinIndex = new KIntNumInput( group1 );
  47. spinIndex->setMaxValue( SPINMAX );
  48. spinIndex->setLabel( i18n( "Start &index:" ), AlignLeft | AlignVCenter );
  49. spinStep = new KIntNumInput( spinIndex, 1, group1 );
  50. spinStep->setRange( -SPINMAX, SPINMAX, 1, false );
  51. spinStep->setValue( 1 );
  52. spinStep->setLabel( i18n( "Step &by:" ), AlignLeft | AlignVCenter );
  53. checkResetCounter = new TQCheckBox( i18n("&Reset counter for every directory"), group1 );
  54. TQGroupBox* group2 = new TQGroupBox( plainPage() );
  55. group2->setTitle( i18n("S&kip Numbers") );
  56. group2->setColumnLayout(0, Qt::Horizontal );
  57. group2->layout()->setSpacing( 6 );
  58. group2->layout()->setMargin( 11 );
  59. TQHBoxLayout* group2Layout = new TQHBoxLayout( group2->layout() );
  60. group2Layout->setAlignment( TQt::AlignTop );
  61. listNumbers = new TDEListBox( group2 );
  62. buttonAdd = new KPushButton( group2 );
  63. buttonAdd->setText( i18n( "&Add Number" ) );
  64. buttonRemove = new KPushButton( group2 );
  65. buttonRemove->setText( i18n( "&Remove Number" ) );
  66. spinNumber = new KMyIntSpinBox( group2 );
  67. spinNumber->setMaxValue( SPINMAX );
  68. spinNumber->setMinValue( -SPINMAX );
  69. spinNumber->setValue( 0 );
  70. spinNumber->setFocus();
  71. TQVBoxLayout* layout2 = new TQVBoxLayout( 0, 6, 6 );
  72. layout2->addWidget( buttonAdd );
  73. layout2->addWidget( buttonRemove );
  74. layout2->addWidget( spinNumber );
  75. layout2->addItem( spacer );
  76. group1Layout->addWidget( spinIndex );
  77. group1Layout->addWidget( spinStep );
  78. group1Layout->addWidget( checkResetCounter );
  79. group2Layout->addWidget( listNumbers );
  80. group2Layout->addLayout( layout2 );
  81. layout->addWidget( group1 );
  82. layout->addWidget( group2 );
  83. TQToolTip::add( spinIndex, i18n( "Number of the first file." ) );
  84. TQToolTip::add( spinStep, i18n( "The counter is increased/decreased by this value." ) );
  85. TQToolTip::add( listNumbers, i18n("Add all numbers that should be skipped by krename during the rename process.<br>"
  86. "E.g.: If 2 is skipped files will be numbered: file0, file1, file3, ...") );
  87. TQToolTip::add( checkResetCounter, i18n("<qt>The counter is set to the start index in every directory. "
  88. "This setting applies to all used counters.</qt>" ) );
  89. connect( buttonAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( addNumber() ) );
  90. connect( buttonRemove,TQT_SIGNAL( clicked() ), this, TQT_SLOT( removeNumber() ) );
  91. connect( spinNumber, TQT_SIGNAL( returnPressed()), this, TQT_SLOT( addNumber() ) );
  92. for( unsigned int i = 0; i < n.count(); i++ )
  93. listNumbers->insertItem( TQString("%1").arg(n[i]), -1 );
  94. update();
  95. }
  96. NumberDialog::~NumberDialog()
  97. {
  98. }
  99. void NumberDialog::addNumber()
  100. {
  101. TQString tmp = TQString("%1").arg(spinNumber->value());
  102. for( unsigned int i = 0; i < listNumbers->count(); i++ )
  103. if( listNumbers->text(i) == tmp )
  104. return;
  105. listNumbers->insertItem( tmp, -1 );
  106. sort();
  107. }
  108. void NumberDialog::removeNumber()
  109. {
  110. unsigned int i = 0;
  111. do {
  112. if(listNumbers->isSelected( i )) {
  113. listNumbers->removeItem( i );
  114. listNumbers->setSelected( i-1, true );
  115. return;
  116. } else
  117. i++;
  118. } while( i < listNumbers->count() );
  119. }
  120. TQValueList<int> NumberDialog::getList()
  121. {
  122. TQValueList<int> skip;
  123. for( unsigned int i = 0; i < listNumbers->count(); i++ )
  124. skip.append( listNumbers->text(i).toInt() );
  125. return skip;
  126. }
  127. void NumberDialog::sort()
  128. {
  129. // Not very fast, but I hope it won't be used on ot big lists ;)
  130. if( listNumbers->count() < 1 )
  131. return;
  132. for( unsigned int i = 0; i < listNumbers->count()-1; i++) {
  133. if( listNumbers->text(i).toInt() > listNumbers->text(i+1).toInt() ) {
  134. TQString tmp = listNumbers->text(i);
  135. listNumbers->removeItem(i);
  136. listNumbers->insertItem( tmp, i+1 );
  137. i = 0;
  138. }
  139. }
  140. }
  141. #include "numberdialog.moc"