Exemplo n.º 1
0
PlotWidget::PlotWidget ()
{
  g_symbol = new Bars;
  
  QVBoxLayout *vbox = new QVBoxLayout;
  vbox->setSpacing(0);
  vbox->setMargin(0);
  setLayout(vbox);
  
  // chart splitter
  _csplitter = new QSplitter(Qt::Vertical, 0);
  _csplitter->setOpaqueResize(FALSE);
  vbox->addWidget(_csplitter);
  
  _cw = new ControlWidget;
  connect(_cw, SIGNAL(signalSelected()), this, SLOT(refresh()));
  connect(_cw, SIGNAL(signalRefresh()), this, SLOT(refresh()));
  connect(_cw, SIGNAL(signalIndicator()), this, SLOT(indicatorDialog()));
  connect(_cw, SIGNAL(signalLength()), this, SLOT(setBarLength()));
  connect(_cw, SIGNAL(signalRange()), this, SLOT(refresh()));
  connect(_cw, SIGNAL(signalScrollBarChanged(int)), this, SLOT(scrollBarChanged(int)));
  connect(_cw, SIGNAL(signalRemovePlot()), this, SLOT(removeIndicator()));
  connect(_cw, SIGNAL(signalEditPlot()), this, SLOT(editIndicator()));
  vbox->addWidget(_cw);
  
  // fix for messed up plot screen if we draw the plot before it has become visible
  // we load settings just after plot is visible with this delay
  QTimer::singleShot(10, this, SLOT(loadSettings()));
}
Exemplo n.º 2
0
//***************************************************************************
QStringList *Kwave::SaveBlocksPlugin::setup(QStringList &previous_params)
{
    // try to interpret the previous parameters
    interpreteParameters(previous_params);

    // create the setup dialog
    sample_index_t selection_left  = 0;
    sample_index_t selection_right = 0;
    selection(0, &selection_left, &selection_right, false);

    // enable the "selection only" checkbox only if there is something
    // selected but not everything
    bool selected_something = (selection_left != selection_right);
    bool selected_all = ((selection_left == 0) &&
                         (selection_right + 1 >= signalLength()));
    bool enable_selection_only = selected_something && !selected_all;

    QString filename = m_url.path();
    QString base = findBase(filename, m_pattern);
    scanBlocksToSave(base, m_selection_only && enable_selection_only);

    QPointer<Kwave::SaveBlocksDialog> dialog =
	new(std::nothrow) Kwave::SaveBlocksDialog(
	    _("kfiledialog:///kwave_save_blocks"),
	    Kwave::CodecManager::encodingFilter(),
	    parentWidget(),
	    QUrl::fromUserInput(signalName()),
	    _("*.wav"),
	    m_pattern,
	    m_numbering_mode,
	    m_selection_only,
	    enable_selection_only
	);
    if (!dialog) return 0;

    // connect the signals/slots from the plugin and the dialog
    connect(dialog, SIGNAL(sigSelectionChanged(QString,
	QString,Kwave::SaveBlocksPlugin::numbering_mode_t,bool)),
	this, SLOT(updateExample(QString,QString,
	Kwave::SaveBlocksPlugin::numbering_mode_t,bool)));
    connect(this, SIGNAL(sigNewExample(QString)),
	dialog, SLOT(setNewExample(QString)));

    dialog->setWindowTitle(i18n("Save Blocks"));
    dialog->emitUpdate();
    if (dialog->exec() != QDialog::Accepted) {
	delete dialog;
	return 0;
    }

    QStringList *list = new QStringList();
    Q_ASSERT(list);
    if (list) {
	// user has pressed "OK"
	QString pattern;

	QUrl url = dialog->selectedUrl();
	if (url.isEmpty()) {
	    delete dialog;
	    return 0;
	}
	QString name = url.path();
	QFileInfo path(name);

	// add the correct extension if necessary
	if (!path.suffix().length()) {
	    QString ext = dialog->selectedExtension();
	    QStringList extensions = ext.split(_(" "));
	    ext = extensions.first();
	    name += ext.mid(1);
	    path = name;
	    url.setPath(name);
	}

	name     = Kwave::Parser::escape(name);
	pattern  = Kwave::Parser::escape(dialog->pattern());
	int mode = static_cast<int>(dialog->numberingMode());
	bool selection_only = (enable_selection_only) ?
	    dialog->selectionOnly() : m_selection_only;

	*list << name;
	*list << pattern;
	*list << QString::number(mode);
	*list << QString::number(selection_only);

	emitCommand(_("plugin:execute(saveblocks,") +
	    name + _(",") + pattern + _(",") +
	    QString::number(mode) + _(",") +
	    QString::number(selection_only) + _(")")
	);
    } else {
	// user pressed "Cancel"
	delete list;
	list = 0;
    }

    if (dialog) delete dialog;
    return list;
}
Exemplo n.º 3
0
//***************************************************************************
int Kwave::SaveBlocksPlugin::start(QStringList &params)
{
    qDebug("SaveBlocksPlugin::start()");

    // interprete the parameters
    int result = interpreteParameters(params);
    if (result) return result;

    QString filename = m_url.path();
    QFileInfo file(filename);
    QString path = file.absolutePath();
    QString ext  = file.suffix();
    QString base = findBase(filename, m_pattern);
    QByteArray sep("/");

    // determine the selection settings
    sample_index_t selection_left  = 0;
    sample_index_t selection_right = 0;
    selection(0, &selection_left, &selection_right, false);

    bool selected_something = (selection_left != selection_right);
    bool selected_all = ((selection_left == 0) &&
                         (selection_right+1 >= signalLength()));
    bool enable_selection_only = selected_something && !selected_all;
    bool selection_only = enable_selection_only && m_selection_only;

    if (selection_only) {
	selection(0, &selection_left, &selection_right, true);
    } else {
	selection_left  = 0;
	selection_right = signalLength() - 1;
    }

    // get the index range
    scanBlocksToSave(base, selection_only);
    unsigned int count = m_block_info.count();
    unsigned int first = firstIndex(path, base, ext, m_pattern,
                                    m_numbering_mode, count);

//     qDebug("m_url            = '%s'", m_url.prettyURL().local8Bit().data());
//     qDebug("m_pattern        = '%s'", m_pattern.local8Bit().data());
//     qDebug("m_numbering_mode = %d", (int)m_numbering_mode);
//     qDebug("selection_only   = %d", selection_only);
//     qDebug("indices          = %u...%u (count=%u)", first, first+count-1,count);

    // iterate over all blocks to check for overwritten files and missing dirs
    QStringList  overwritten_files;
    QStringList  missing_dirs;
    for (unsigned int i = first; i < (first + count); i++) {
	QString name = createFileName(base, ext, m_pattern, i, count,
	                              first + count - 1);
	QString display_name = Kwave::Parser::unescape(name);

	// split the name into directory and file name
	name = QString::fromLatin1(QUrl::toPercentEncoding(display_name, sep));
	QUrl url = m_url.adjusted(QUrl::RemoveFilename);
	url.setPath(url.path(QUrl::FullyEncoded) + name, QUrl::StrictMode);

	QString filename = url.path();
	QFileInfo file_info(filename);

	// check for potentially overwritten file
	if (file_info.exists())
	    overwritten_files += Kwave::Parser::unescape(display_name);

	// check for missing subdirectory
	if (!file_info.dir().exists()) {
	    QFileInfo inf(display_name);
	    QString missing_dir = inf.path();
	    if (!missing_dirs.contains(missing_dir))
		missing_dirs += missing_dir;
	}
    }

    // inform about overwritten files
    if (!overwritten_files.isEmpty()) {
	// ask the user for confirmation if he really wants to overwrite...
	if (Kwave::MessageBox::warningYesNo(parentWidget(),
	    _("<html>") +
	    i18n("This would overwrite the following file(s): %1" \
	    "Do you really want to continue?",
	    createDisplayList(overwritten_files, 5)) +
	    _("</html>") ) != KMessageBox::Yes)
	{
	    return -1;
	}
    }

    // handle missing directories
    if (!missing_dirs.isEmpty()) {
	// ask the user if he wants to continue and create the directory
	if (Kwave::MessageBox::warningContinueCancel(parentWidget(),
	    i18n("The following directories do not exist: %1"
	         "Do you want to create them and continue?",
	         createDisplayList(missing_dirs, 5)),
	    QString(),
	    QString(),
	    QString(),
	    _("saveblocks_create_missing_dirs")
	    ) != KMessageBox::Continue)
	{
	    return -1;
	}

	// create all missing directories
	QUrl base_url = m_url.adjusted(QUrl::RemoveFilename);
	foreach (const QString &missing, missing_dirs) {
	    QUrl url(base_url);
	    url.setPath(
		base_url.path(QUrl::FullyEncoded) +
		QString::fromLatin1(QUrl::toPercentEncoding(missing)),
		QUrl::StrictMode
	    );
	    QString path = url.path();
	    QDir dir;
	    if (!dir.mkpath(path))
		qWarning("creating path '%s' failed", DBG(path));
	}
    }