TDE graphics utilities
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.

loadpalettedlg.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /***************************************************************************
  2. loadpalettedlg.cpp - description
  3. -------------------
  4. begin : Sat Jul 8 2000
  5. copyright : (C) 2000 by Artur Rataj
  6. email : art@zeus.polsl.gliwice.pl
  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 <string.h>
  17. #include <tqlayout.h>
  18. #include <tqlabel.h>
  19. #include <tqstring.h>
  20. #include <tqstringlist.h>
  21. #include <tqpushbutton.h>
  22. #include <klocale.h>
  23. #include <kstandarddirs.h>
  24. #include <kpalette.h>
  25. #include <tdefiledialog.h>
  26. #include "main.h"
  27. #include "palette.h"
  28. #include "loadpalettedlg.h"
  29. LoadPaletteDlg::LoadPaletteDlg(TQWidget *parent, const char *name)
  30. : KDialogBase(parent, name, true, i18n( "Load Palette" ),
  31. Ok|Cancel, Ok, true) {
  32. fileName = "";
  33. TQWidget *mainWidget = new TQWidget( this );
  34. setMainWidget( mainWidget );
  35. TQVBoxLayout* topLayout = new TQVBoxLayout(mainWidget, 0, spacingHint());
  36. TQLabel* label = new TQLabel(i18n( "Select a palette:" ), mainWidget);
  37. topLayout->addWidget(label);
  38. paletteBox = new TQComboBox(false, mainWidget);
  39. browseFileNameInserted = false;
  40. TQStringList palettesList = Palette::kdePalettes();
  41. for(TQStringList::Iterator palette = palettesList.begin();
  42. palette != palettesList.end(); ++palette) {
  43. bool prepend = (*palette).contains( "colors/Custom_Colors" );
  44. TQString fileName = locate("config", (*palette));
  45. if(prepend) {
  46. palettesFileNames.prepend(fileName);
  47. setFileName(&fileName);
  48. } else {
  49. palettesFileNames.append(fileName);
  50. if(palette == palettesList.begin())
  51. setFileName(&fileName);
  52. }
  53. TQString paletteName = (*palette).mid(palettesDir.length() + 1);
  54. if(paletteName == "Custom_Colors")
  55. paletteName = i18n("Custom Colors");
  56. else if(paletteName == "Recent_Colors")
  57. paletteName = i18n("Recent Colors");
  58. if(prepend)
  59. paletteBox->insertItem(paletteName, 0);
  60. else
  61. paletteBox->insertItem(paletteName);
  62. }
  63. connect(paletteBox, TQT_SIGNAL( activated(int) ), TQT_SLOT( setFileName(int) ));
  64. topLayout->addWidget(paletteBox);
  65. TQHBoxLayout* browseLayout = new TQHBoxLayout( mainWidget );
  66. TQPushButton* browseButton = new TQPushButton(i18n( "Browse..." ),
  67. mainWidget);
  68. connect(browseButton, TQT_SIGNAL( clicked() ), TQT_SLOT( browseFileNames() ));
  69. browseLayout->addWidget(browseButton);
  70. browseLayout->addStretch(10);
  71. topLayout->addLayout(browseLayout);
  72. topLayout->addStretch(10);
  73. resize(300, 155);
  74. }
  75. LoadPaletteDlg::~LoadPaletteDlg() {
  76. }
  77. void LoadPaletteDlg::setFileName(TQString* fileName) {
  78. this->fileName = *fileName;
  79. }
  80. void LoadPaletteDlg::setFileName(int index) {
  81. setFileName(&palettesFileNames[index]);
  82. }
  83. void LoadPaletteDlg::browseFileNames() {
  84. TQString fileToOpen = KFileDialog::getOpenFileName(lastOpenPaletteFileDir,
  85. i18n("*|All Files"), this, i18n("Open File"));
  86. if(!fileToOpen.isEmpty()) {
  87. fileName = fileToOpen;
  88. if(browseFileNameInserted) {
  89. paletteBox->removeItem(0);
  90. palettesFileNames.remove(palettesFileNames.begin());
  91. }
  92. paletteBox->insertItem(fileName, 0);
  93. paletteBox->setCurrentItem(0);
  94. palettesFileNames.prepend(fileName);
  95. browseFileNameInserted = true;
  96. lastOpenPaletteFileDir = fileName;
  97. }
  98. }
  99. TQString LoadPaletteDlg::getFileName() {
  100. return fileName;
  101. }
  102. #include "loadpalettedlg.moc"