Source Code (Use browser search to find items of interest.)

Class Index

kab'KDataNavigator (./kdeutils/kab/widget_datanavigator.h:88)

class KDataNavigator : public QFrame
{
  // ############################################################################
  Q_OBJECT
  // ----------------------------------------------------------------------------
public:
  /** The three possible operation modes. */
  enum Modes {
    Index, /**< Index mode. */
    List, /**< List mode. */
    Manual /**< Mode for manual insertion of text. */
  };
  /** The Qt standard constructor. */
  KDataNavigator(QWidget* parent=0, const char* name=0);
  ~KDataNavigator(); /**< The destructor. */
  QSize sizeHint(); /**< The size hint. The button width is fixed to 20. */
  void setMode(Modes mode); /**< Select the mode the widget operates in. */
  /** Set the text of the central lineedit in text mode. If you call ::setText(),
   *  the index mode is disabled. */
  void setText(const char*);
  /** Set the list of strings displayed in the combobox in list mode. */
  void setList(QStringList*);
  /** Enable index mode, giving the range and the current elements index.
   *  If \e state is false, index mode is disabled. */
  void setIndexMode(int begin, int end, int current);
  /** Hide or show the button for creating a new item. */
  void showButtonNew(bool state);
  void enableButtonFirst(bool state); /**< Hide or show button \e first. */
  void enableButtonNext(bool state); /**< Hide or show button \e next. */
  void enableButtonPrevious(bool state); /**< Hide or show button \e previous. */
  void enableButtonLast(bool state); /**< Hide or show button \e last. */
  void enableButtonNew(bool state); /**< Hide or show button \e new. */
  // ----------------------------------------------------------------------------
signals:
  void first(); /**< Button \e first has been pressed. */
  void previous(); /**< Button \e previous has been pressed. */
  void next(); /**< Button \e next has been pressed. */
  void last(); /**< Button \e last has been pressed. */
  void newItem(); /**< Button \e new \e item has been pressed. */
  void itemSelected(int); /**< The item with the given index has been selected.*/
  void textChanged(const QString&); /**< Emitted in manual mode. */
  // ----------------------------------------------------------------------------
protected:
  // ----- events:
  void resizeEvent(QResizeEvent*); /**< The resize event. */
  void setLayout(); /**< \internal */
  void enableButtons(); /**< \internal */
  // ----- members:
  QPushButton *buttonFirst; /**< The button for selecting the first element. */
  QPushButton *buttonPrevious; /**< The button for selecting the previous element. */
  QPushButton *buttonNext; /**< The button for selecting the next element. */
  QPushButton *buttonLast; /**< The button for selecting the last element. */
  QPushButton *buttonNew; /**< The button for inserting a new element. */
  QLineEdit *leIndex; /**< The lineedit displayed in manual mode. */
  QSpinBox *sbIndex; /**< The spin box displayed in index mode. */
  QComboBox *cbIndex; /**< The combobox display in list mode. */
  int min; /**< The smallest possible index. */
  int max; /**< The largest possible index. */
  int current; /**< The current index. */
  Modes mode; /**< The selected mode (default: Manual). */
  bool buttonNewVisible; /**< Wether the \e new button is displayed. */
  // ----------------------------------------------------------------------------
protected slots:
  void buttonFirstClicked(); /**< \internal */
  void buttonPreviousClicked(); /**< \internal */
  void buttonNextClicked(); /**< \internal */
  void buttonLastClicked(); /**< \internal */
  void buttonNewClicked(); /**< \internal */
  void leTextChanged(const QString&); /**< \internal */
  void sbValueChanged(int); /**< \internal */
  void cbItemSelected(int); /**< \internal */
  // ############################################################################
};

kab'KDataNavigator::KDataNavigator() (./kdeutils/kab/widget_datanavigator.cc:38)

KDataNavigator::KDataNavigator(QWidget* parent, const char* name)
  : QFrame(parent, name),
    buttonFirst(new QPushButton(this)),
    buttonPrevious(new QPushButton(this)),
    buttonNext(new QPushButton(this)),
    buttonLast(new QPushButton(this)),
    buttonNew(new QPushButton(this)),
    leIndex(new QLineEdit(this)),
    sbIndex(new QSpinBox(this)),
    cbIndex(new QComboBox(this)),
    min(0),
    max(0),
    current(0),
    mode(Manual),
    buttonNewVisible(true)
{
  // ###########################################################################
  QPushButton* buttons[]= {
    buttonFirst, buttonPrevious, buttonNext, buttonLast, buttonNew
  };
  const char* icons[]= {
    // "2leftarrow", "1leftarrow", "1rightarrow", "2rightarrow", "filenew2"
    "start", "back", "forward", "finish", "filenew2"
  };
  int count;
  QPixmap pixmap;
  // -----
  if(buttonFirst==0 || buttonPrevious==0 || buttonNext==0 || buttonLast==0 ||
     buttonNew==0 || leIndex==0 || sbIndex==0 || cbIndex==0)
    {
      // possibly throw exception when they are completely implemented
    }
  leIndex->setEnabled(false);
  for(count=0; count<5; ++count)
    {
      pixmap=BarIcon(icons[count]);
      if(!pixmap.isNull())
	{
	  buttons[count]->setPixmap(pixmap);
	}
    }
  // -----
  connect(buttonFirst, SIGNAL(clicked()), SLOT(buttonFirstClicked()));
  connect(buttonPrevious, SIGNAL(clicked()), SLOT(buttonPreviousClicked()));
  connect(buttonNext, SIGNAL(clicked()), SLOT(buttonNextClicked()));
  connect(buttonLast, SIGNAL(clicked()), SLOT(buttonLastClicked()));
  connect(buttonNew, SIGNAL(clicked()), SLOT(buttonNewClicked()));
  connect(leIndex, SIGNAL(textChanged(const QString&)),
	  SLOT(leTextChanged(const QString&)));
  connect(cbIndex, SIGNAL(activated(int)), SLOT(cbItemSelected(int)));
  connect(sbIndex, SIGNAL(valueChanged(int)), SLOT(sbValueChanged(int)));
  // -----
  setFrameStyle(QFrame::Box | QFrame::Plain);
  setLineWidth(1);
  enableButtons();
  // ###########################################################################
}


kab'KDataNavigator::~KDataNavigator() (./kdeutils/kab/widget_datanavigator.cc:96)

KDataNavigator::~KDataNavigator()
{
  // ###########################################################################
  // ###########################################################################
}

void

kab'KDataNavigator::resizeEvent() (./kdeutils/kab/widget_datanavigator.cc:103)

KDataNavigator::resizeEvent(QResizeEvent*)
{
  // ###########################################################################
  setLayout();
  // ###########################################################################
}

void

kab'KDataNavigator::setLayout() (./kdeutils/kab/widget_datanavigator.cc:111)

KDataNavigator::setLayout()
{
  // ###########################################################################
  // ----- sorry for the bad construct:
  //       the layout management should be moved to QLayout to be more readable:
  QWidget *widgets[]= {
    buttonFirst, buttonPrevious,
    mode==Manual ? leIndex : (mode==List
			      ? (QWidget*)cbIndex
			      : (QWidget*)sbIndex), 
    buttonNext, buttonLast, buttonNew
  };
  const int NoOfElements=sizeof(widgets)/sizeof(widgets[0]);
  const int NoOfButtons= buttonNewVisible ? 5 : 4;
  int count, w=0, h=0;
  // ----- find size hints of buttons in h and w:
  for(count=0; count<NoOfElements; ++count)
    {
      h=QMAX(h, widgets[count]->sizeHint().height());
      if(count!=2) // except combobox
	{
	  w=QMAX(w, widgets[count]->sizeHint().width());
	}
    }
  // ----- calculate heights and widths finally:
  const int ButtonHeight= h>0 ? h : height()-2*frameWidth();
  const int ButtonWidth= w>0 ? w : h;
  int widths[]= {
    ButtonWidth, ButtonWidth,
    width()-2*frameWidth()-(NoOfButtons)*ButtonWidth,
    ButtonWidth, ButtonWidth, buttonNewVisible ? ButtonWidth : 0
  };
  h=height()-2*frameWidth();
  if(h>ButtonHeight) h=ButtonHeight;
  int heights[]= { h, h, widgets[2]->sizeHint().height(), h, h, h };
  int cx, offset;
  // -----
  cx=frameWidth();
  for(count=0; count<NoOfElements; ++count)
    {
      if(count==2)
	{
	  offset=(height()-heights[count])/2;
	  // this will look ugly as the combo does not fit:
	  if(offset<=0) offset=frameWidth();
	} else {
	  offset=frameWidth();
	}
      widgets[count]->setGeometry(cx, offset, widths[count], heights[count]);
      cx+=widths[count];
    }  
  // ###########################################################################
}


QSize

kab'KDataNavigator::sizeHint() (./kdeutils/kab/widget_datanavigator.cc:167)

KDataNavigator::sizeHint()
{
  // ###########################################################################
  const int ButtonWidth=20; // KButtons do not seem to report it
  const int NoOfButtons= buttonNewVisible ? 5 : 4;
  // -----
  switch(mode)
    {
    case Manual:
      return QSize((NoOfButtons+6)*ButtonWidth+2*frameWidth(),
		   ButtonWidth+2*frameWidth());
    case List:
      return QSize((NoOfButtons+8)*ButtonWidth+2*frameWidth(),
		   ButtonWidth+2*frameWidth());
    default:
      return QSize((NoOfButtons+4)*ButtonWidth+2*frameWidth(),
		   ButtonWidth+2*frameWidth());
    }
  // ###########################################################################
}

void

kab'KDataNavigator::buttonFirstClicked() (./kdeutils/kab/widget_datanavigator.cc:189)

KDataNavigator::buttonFirstClicked()
{
  // ###########################################################################
  switch(mode)
    {
    case Manual: // the most easy case: do nothing
      break;
    case Index:
      if(min<current)
	{
	  current=min;
	  emit(itemSelected(current));
	  sbIndex->setValue(current);
	  enableButtons();
	} else {
	  kapp->beep(); // cannot happen
	}
      break;
    case List:
      if(current>0 && cbIndex->count()>0)
	{
	  current=0;
	  cbIndex->setCurrentItem(current);
	  emit(itemSelected(current));
	  enableButtons();
	}
      break;
    }
  emit(first());
  // ###########################################################################
}

void

kab'KDataNavigator::buttonPreviousClicked() (./kdeutils/kab/widget_datanavigator.cc:222)

KDataNavigator::buttonPreviousClicked()
{
  // ###########################################################################
  switch(mode)
    {
    case Manual:
      break;
    case Index:
      if(min<current)
	{
	  --current;
	  emit(itemSelected(current));
	  sbIndex->setValue(current);
	  enableButtons();
	} else {
	  kapp->beep();
	}
      break;
    case List:
      if(current>0 && cbIndex->count()>0)
	{
	  --current;
	  cbIndex->setCurrentItem(current);
	  emit(itemSelected(current));
	  enableButtons();
	}  
      break;
    }
  emit(previous());
  // ###########################################################################
}

void

kab'KDataNavigator::buttonNextClicked() (./kdeutils/kab/widget_datanavigator.cc:255)

KDataNavigator::buttonNextClicked()
{
  // ###########################################################################
  switch(mode)
    {
    case Manual:
      break;
    case Index:
      if(current<max)
	{
	  ++current;
	  emit(itemSelected(current));
	  sbIndex->setValue(current);
	  enableButtons();
	} else {
	  kapp->beep();
	}
      break;
    case List:
      if(current<cbIndex->count()-1 && cbIndex->count()>0)
	{
	  ++current;
	  cbIndex->setCurrentItem(current);
	  emit(itemSelected(current));
	  enableButtons();
	}      
      break;
    }
  emit(next());
  // ###########################################################################
}

void

kab'KDataNavigator::buttonLastClicked() (./kdeutils/kab/widget_datanavigator.cc:288)

KDataNavigator::buttonLastClicked()
{
  // ###########################################################################
  switch(mode)
    {
    case Manual:
      break;
    case Index:
      if(current<max)
	{
	  current=max;
	  emit(itemSelected(current));
	  sbIndex->setValue(current);
	  enableButtons();
	} else {
	  kapp->beep();
	}
      break;
    case List:
      if(current<cbIndex->count()-1 && cbIndex->count()>0)
	{
	  current=cbIndex->count()-1;
	  cbIndex->setCurrentItem(current);
	  emit(itemSelected(current));
	  enableButtons();
	}      
      break;
    }
  emit(last());
  // ###########################################################################
}

void

kab'KDataNavigator::buttonNewClicked() (./kdeutils/kab/widget_datanavigator.cc:321)

KDataNavigator::buttonNewClicked()
{
  // ###########################################################################
  emit(newItem());
  // ###########################################################################
}

void

kab'KDataNavigator::setText() (./kdeutils/kab/widget_datanavigator.cc:329)

KDataNavigator::setText(const char* c)
{
  // ###########################################################################
  setMode(Manual);
  leIndex->setText(c);
  // ###########################################################################
}

void

kab'KDataNavigator::setIndexMode() (./kdeutils/kab/widget_datanavigator.cc:338)

KDataNavigator::setIndexMode(int begin, int end, int cur)
{
  // ###########################################################################
  min=begin;
  max=end;
  current=cur;
  sbIndex->setRange(min, max);
  if(min<=current && current<=max)
    {
      sbIndex->setValue(current);
    } else {
      sbIndex->setValue(min);
    }
  leIndex->hide();
  cbIndex->hide();
  sbIndex->show();
  // -----
  mode=Index;
  enableButtons();
  // ###########################################################################
}

void

kab'KDataNavigator::showButtonNew() (./kdeutils/kab/widget_datanavigator.cc:361)

KDataNavigator::showButtonNew(bool state)
{
  // ###########################################################################
  if(state)
    {
      buttonNew->show();
    } else {
      buttonNew->hide();
    }  
  buttonNewVisible=state;
  // -----
  setLayout();
  // ###########################################################################
}

void

kab'KDataNavigator::enableButtonFirst() (./kdeutils/kab/widget_datanavigator.cc:377)

KDataNavigator::enableButtonFirst(bool state)
{
  // ###########################################################################
  buttonFirst->setEnabled(state);
  // ###########################################################################
}
  
void

kab'KDataNavigator::enableButtonNext() (./kdeutils/kab/widget_datanavigator.cc:385)

KDataNavigator::enableButtonNext(bool state)
{
  // ###########################################################################
  buttonNext->setEnabled(state);
  // ###########################################################################
}
  
void

kab'KDataNavigator::enableButtonPrevious() (./kdeutils/kab/widget_datanavigator.cc:393)

KDataNavigator::enableButtonPrevious(bool state)
{
  // ###########################################################################
  buttonPrevious->setEnabled(state);
  // ###########################################################################
}
  
void

kab'KDataNavigator::enableButtonLast() (./kdeutils/kab/widget_datanavigator.cc:401)

KDataNavigator::enableButtonLast(bool state)
{
  // ###########################################################################
  buttonLast->setEnabled(state);
  // ###########################################################################
}
  
void

kab'KDataNavigator::enableButtonNew() (./kdeutils/kab/widget_datanavigator.cc:409)

KDataNavigator::enableButtonNew(bool state)
{
  // ###########################################################################
  buttonNew->setEnabled(state);
  // ###########################################################################
}

void

kab'KDataNavigator::enableButtons() (./kdeutils/kab/widget_datanavigator.cc:417)

KDataNavigator::enableButtons()
{
  // ###########################################################################
  switch(mode)
    {
    case Manual:
      break;
    case Index:
      buttonFirst->setEnabled(current!=min);
      buttonPrevious->setEnabled(current!=min);
      buttonNext->setEnabled(current!=max);
      buttonLast->setEnabled(current!=max);
      break;
    case List:
      buttonFirst->setEnabled(current!=0);
      buttonPrevious->setEnabled(current!=0);
      buttonNext->setEnabled(current!=cbIndex->count()-1 && cbIndex->count()>0);
      buttonLast->setEnabled(current!=cbIndex->count()-1 && cbIndex->count()>0);
      cbIndex->setEnabled(cbIndex->count()>0);
      break;
    }
  // ###########################################################################
}
  
void

kab'KDataNavigator::leTextChanged() (./kdeutils/kab/widget_datanavigator.cc:442)

KDataNavigator::leTextChanged(const QString& s)
{
  // ###########################################################################
  emit(textChanged(s));
  // ###########################################################################
}

void

kab'KDataNavigator::sbValueChanged() (./kdeutils/kab/widget_datanavigator.cc:450)

KDataNavigator::sbValueChanged(int i)
{
  // ###########################################################################
  if(min<=i && i<=max)
    {
      current=i;
      enableButtons();
      emit(itemSelected(i));
    }
  // ###########################################################################
}

void

kab'KDataNavigator::cbItemSelected() (./kdeutils/kab/widget_datanavigator.cc:463)

KDataNavigator::cbItemSelected(int i)
{
  // ###########################################################################
  current=i;
  enableButtons();
  emit(itemSelected(i));
  // ###########################################################################
}

void

kab'KDataNavigator::setMode() (./kdeutils/kab/widget_datanavigator.cc:473)

KDataNavigator::setMode(Modes m)
{
  // ###########################################################################
  mode=m;
  switch(mode)
    {
    case Manual:
      leIndex->show();
      sbIndex->hide();
      cbIndex->hide();
      buttonFirst->setEnabled(true);
      buttonPrevious->setEnabled(true);
      buttonNext->setEnabled(true);
      buttonLast->setEnabled(true);
      break;
    case Index:
      leIndex->hide();
      sbIndex->show();
      cbIndex->hide();
      break;
    case List:
      leIndex->hide();
      sbIndex->hide();
      cbIndex->show();
      break;
    }
  enableButtons();
  setLayout();
  // ###########################################################################
}

void

kab'KDataNavigator::setList() (./kdeutils/kab/widget_datanavigator.cc:505)

KDataNavigator::setList(QStringList* strings)
{
  register bool GUARD; GUARD=false;
  // ###########################################################################
  kDebugInfo(GUARD, 0, "KDataNavigator::setList: called, %i items.",
	     strings->count());
  // -----
  if(cbIndex->count()>0) cbIndex->clear();
  cbIndex->insertStringList(*strings);
  if(cbIndex->count()>0)
    {
      cbIndex->setCurrentItem(0);
      current=0;
    }
  setMode(List);
  // ###########################################################################
}