QWidget* PathChooserDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(index)

    QTreeWidgetItem *item = tree_->currentItem();
    if (!item) {
        return NULL;
    }
    path_item_ = item;

    path_editor_ = new QWidget(parent);
    QHBoxLayout *hbox = new QHBoxLayout(path_editor_);
    path_editor_->setLayout(hbox);
    path_le_ = new QLineEdit(path_editor_);
    QPushButton *pb = new QPushButton(path_editor_);

    path_le_->setText(item->text(col_p_pipe_));
    pb->setText(QString(tr("Browse...")));

    hbox->setContentsMargins(0, 0, 0, 0);
    hbox->addWidget(path_le_);
    hbox->addWidget(pb);
    hbox->setSizeConstraint(QLayout::SetMinimumSize);

    // Grow the item to match the editor. According to the QAbstractItemDelegate
    // documenation we're supposed to reimplement sizeHint but this seems to work.
    QSize size = option.rect.size();
    size.setHeight(qMax(option.rect.height(), hbox->sizeHint().height()));
    item->setData(col_p_pipe_, Qt::SizeHintRole, size);

    path_le_->selectAll();
    path_editor_->setFocusProxy(path_le_);
    path_editor_->setFocusPolicy(path_le_->focusPolicy());

    connect(path_le_, SIGNAL(destroyed()), this, SLOT(stopEditor()));
    connect(pb, SIGNAL(pressed()), this, SLOT(browse_button_clicked()));
    return path_editor_;
}
Example #2
0
/*! Makes a scrolled text window with the text taken from the array of 
  character strings in [msg] */
void dia_smsg(const char **msg)
{
  char *p;
  char *buf;
  char *lineStart;
  char *temp;
  int maxline, maxrow, linesize;
  long bufsize;
  int i, twidth, doline;
  int lastspace, curpos;
  int maxWidth = (int)(0.8 * QApplication::desktop()->width());
  int maxHeight = (int)(0.8 * QApplication::desktop()->height());
  int height, width = 0;
  QString test;

  QDialog *dlg = new QDialog();
  dlg->setAttribute(Qt::WA_DeleteOnClose);

  for (i = 0, bufsize = 0; msg[i]; i++){
    linesize = strlen(msg[i]);
    bufsize += linesize;
  }

  buf = (char *)malloc(bufsize + i + 1);
  p = buf;
  for (p = buf, i = 0; msg[i]; i++) {
    p += strlen (strcpy (p, msg[i]));
    /* DNM: this macro call caused program built on Irix 6.5 to not run
       on earlier Irix's.  Casting as (int) didn't help - just do 
       explicit tests */
    /*if (!isspace (p[-1]))  spaces, tabs and newlines are spaces.. */
    if (p[-1] != ' ' && p[-1] != '\t' && p[-1] != '\n')
      *p++ = ' '; /* lines are concatenated, insert a space */
  }
  *--p = 0; /* get rid of trailing space... */

  // DNM: count the actual lines and their lengths to get the right size window

  maxline = 0;
  maxrow = 1;
  curpos = 0;
  lastspace = 40;
  lineStart = buf;

  for (p = buf; *p; p++) {
    doline = 0;
    if (*p == '\t')
      curpos = 8 * (curpos/ 8 + 1);
    else if (*p == ' ') {
      lastspace = curpos;
      curpos++;
    } else if (*p == '\n') {
      if (curpos >= maxline)
        maxline = curpos + 1;
      curpos = 0;
      doline = p + 1 - lineStart;
    } else if (curpos > 78 ) {
      if (lastspace >= maxline)
        maxline = lastspace + 1;
      curpos -= lastspace;
      doline = lastspace;
    } else
      curpos++;
    
    if (doline) {
      temp = (char *)malloc(doline + 1);
      if (temp) {
	strncpy(temp, lineStart, doline);
	temp[doline] = 0x00;
	test = temp;
	twidth = dlg->fontMetrics().width(test);
	if (width < twidth)
	  width = twidth;
	free(temp);
      }
      lineStart = p + 1;
      lastspace = 40;
      maxrow++;
    }
  }

  if (!maxline & !width) {
    maxline = curpos + 1;
    test = "";
    for (i = 0; i < maxline + 2; i++)
      test += "8";
    width = dlg->fontMetrics().width(test);
  }

  if (maxrow > 50)
    maxrow = 40;

  QString qmsg = buf;

  // Make a vertical layout with the text edit and a close button
  QVBoxLayout *vbox = new QVBoxLayout(dlg);
  QTextEdit *edit = new QTextEdit(dlg);
  edit->setText(qmsg);
  edit->setReadOnly(true);
  vbox->addWidget(edit);
  QHBoxLayout *hbox = diaHBoxLayout(vbox);
  QPushButton *button = diaPushButton("Close", dlg, hbox);
  diaSetButtonWidth(button, true, 1.4, "Close");
  QObject::connect(button, SIGNAL(clicked()), dlg, SLOT(close()));

  // Figure out width and height of text and height of button, and set size
  if (width > maxWidth)
    width = maxWidth;
  height = (maxrow + 5) * edit->fontMetrics().height();
  if (height > maxHeight)
    height = maxHeight;
  QSize hint = hbox->sizeHint();

  // This was width + 20 when the width was based on character count alone
  dlg->resize(width + 60, height + hint.height());

  // Set title
  test = Dia_title;
  test += " Help";
  dlg->setWindowTitle(test);
  dlg->show();
}
Example #3
0
    VideoWidget::VideoWidget(MediaPlayer* player, KActionCollection* ac, QWidget* parent)
        : QWidget(parent), player(player), chunk_bar(0), fullscreen(false),
          screensaver_cookie(0), powermanagement_cookie(0)
    {
        QVBoxLayout* vlayout = new QVBoxLayout(this);
        vlayout->setMargin(0);
        vlayout->setSpacing(0);

        video = new Phonon::VideoWidget(this);
        Phonon::createPath(player->media0bject(), video);
        video->installEventFilter(this);

        chunk_bar = new VideoChunkBar(player->getCurrentSource(), this);
        chunk_bar->setVisible(player->media0bject()->currentSource().type() == Phonon::MediaSource::Stream);

        QHBoxLayout* hlayout = new QHBoxLayout(0);

        play_action = new QAction(QIcon::fromTheme("media-playback-start"), i18n("Play"), this);
        connect(play_action, SIGNAL(triggered()), this, SLOT(play()));

        stop_action = new QAction(QIcon::fromTheme("media-playback-stop"), i18n("Stop"), this);
        connect(stop_action, SIGNAL(triggered()), this, SLOT(stop()));

        tb = new KToolBar(this);
        tb->setToolButtonStyle(Qt::ToolButtonIconOnly);
        tb->addAction(play_action);
        tb->addAction(ac->action("media_pause"));
        tb->addAction(stop_action);
        QAction* tfs = ac->action("video_fullscreen");
        connect(tfs, SIGNAL(toggled(bool)), this, SIGNAL(toggleFullScreen(bool)));
        tb->addAction(tfs);

        slider = new Phonon::SeekSlider(this);
        slider->setMediaObject(player->media0bject());
        slider->setMaximumHeight(tb->iconSize().height());

        volume = new Phonon::VolumeSlider(this);
        volume->setAudioOutput(player->output());
        volume->setMaximumHeight(tb->iconSize().height());
        volume->setMaximumWidth(5 * tb->iconSize().width());

        time_label = new QLabel(this);
        time_label->setText(formatTime(player->media0bject()->currentTime(), player->media0bject()->totalTime()));
        time_label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);

        hlayout->addWidget(tb);
        hlayout->addWidget(slider);
        hlayout->addWidget(volume);
        hlayout->addWidget(time_label);

        chunk_bar->setFixedHeight(hlayout->sizeHint().height() * 0.75);

        vlayout->addWidget(chunk_bar);
        vlayout->addWidget(video);
        vlayout->addLayout(hlayout);

        connect(player->media0bject(), SIGNAL(tick(qint64)), this, SLOT(timerTick(qint64)));
        connect(player, SIGNAL(playing(MediaFileRef)), this, SLOT(playing(MediaFileRef)));
        connect(player, SIGNAL(enableActions(unsigned int)), this, SLOT(enableActions(unsigned int)));
        inhibitScreenSaver(true);
    }