Commit 1e71f45d authored by Urs Fleisch's avatar Urs Fleisch
Browse files

no more dependencies on Qt3Support module when building with Qt 4

parent 3dec56ec
......@@ -10,7 +10,8 @@
#include "commandstable.h"
#if QT_VERSION >= 0x040000
#include <Q3PopupMenu>
#include <QMenu>
#include <QHeaderView>
#else
#include <qpopupmenu.h>
#endif
......@@ -27,12 +28,29 @@ enum ColumnIndex {
/**
* Constructor.
*
* @param title title
* @param parent parent widget
* @param name Qt object name
*/
CommandsTable::CommandsTable(QWidget* parent, const char* name) :
Q3Table(parent, name) {
#if QT_VERSION >= 0x040000
CommandsTable::CommandsTable(QWidget* parent) :
QTableWidget(parent)
{
setColumnCount(CI_NumColumns);
setHorizontalHeaderLabels(
QStringList() << i18n("Confirm") << i18n("Output") << i18n("Name") <<
i18n("Command"));
resizeColumnToContents(CI_Confirm);
resizeColumnToContents(CI_Output);
horizontalHeader()->setResizeMode(CI_Command, QHeaderView::Stretch);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(cellActivated(int, int)),
this, SLOT(valueChanged(int, int)));
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(customContextMenu(const QPoint&)));
}
#else
CommandsTable::CommandsTable(QWidget* parent) :
QTable(parent)
{
setNumCols(CI_NumColumns);
horizontalHeader()->setLabel(CI_Confirm, i18n("Confirm"));
horizontalHeader()->setLabel(CI_Output, i18n("Output"));
......@@ -47,6 +65,7 @@ CommandsTable::CommandsTable(QWidget* parent, const char* name) :
connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint&)),
this, SLOT(contextMenu(int, int, const QPoint&)));
}
#endif
/**
* Destructor.
......@@ -62,6 +81,22 @@ CommandsTable::~CommandsTable() {}
* @param row table row of changed item
* @param col table column of changed item
*/
#if QT_VERSION >= 0x040000
void CommandsTable::valueChanged(int row, int col)
{
QTableWidgetItem* twi;
if (row == rowCount() - 1 && col == CI_Command &&
(twi = item(row, col)) != 0) {
if (twi->text().isEmpty()) {
if (row != 0) {
deleteRow(row);
}
} else {
addRow(row);
}
}
}
#else
void CommandsTable::valueChanged(int row, int col)
{
if (row == numRows() - 1 && col == CI_Command) {
......@@ -70,21 +105,49 @@ void CommandsTable::valueChanged(int row, int col)
deleteRow(row);
}
} else {
insertRow(row);
addRow(row);
}
}
}
#endif
/**
* Insert a new row into the table.
*
* @param row the new row is inserted after this row
*/
void CommandsTable::insertRow(int row)
void CommandsTable::addRow(int row)
{
#if QT_VERSION >= 0x040000
insertRow(row + 1);
QTableWidgetItem* twi;
if ((twi = item(row + 1, CI_Confirm)) == 0) {
twi = new QTableWidgetItem;
setItem(row + 1, CI_Confirm, twi);
}
twi->setCheckState(Qt::Unchecked);
if ((twi = item(row + 1, CI_Output)) == 0) {
twi = new QTableWidgetItem;
setItem(row + 1, CI_Output, twi);
}
twi->setCheckState(Qt::Unchecked);
if ((twi = item(row + 1, CI_Name)) != 0)
twi->setText("");
else
setItem(row + 1, CI_Name, new QTableWidgetItem(""));
if ((twi = item(row + 1, CI_Command)) != 0)
twi->setText("");
else
setItem(row + 1, CI_Command, new QTableWidgetItem(""));
#else
insertRows(row + 1);
setItem(row + 1, CI_Confirm, new Q3CheckTableItem(this, ""));
setItem(row + 1, CI_Output, new Q3CheckTableItem(this, ""));
setItem(row + 1, CI_Confirm, new QCheckTableItem(this, ""));
setItem(row + 1, CI_Output, new QCheckTableItem(this, ""));
#endif
}
/**
......@@ -94,6 +157,9 @@ void CommandsTable::insertRow(int row)
*/
void CommandsTable::deleteRow(int row)
{
#if QT_VERSION >= 0x040000
if (rowCount() <= 1) return;
#endif
removeRow(row);
}
......@@ -104,19 +170,60 @@ void CommandsTable::deleteRow(int row)
*/
void CommandsTable::clearRow(int row)
{
#if QT_VERSION >= 0x040000
QTableWidgetItem* twi = item(row, CI_Name);
if (twi) twi->setText("");
twi = item(row, CI_Command);
if (twi) twi->setText("");
twi = item(row, CI_Confirm);
if (twi) twi->setCheckState(Qt::Unchecked);
twi = item(row, CI_Output);
if (twi) twi->setCheckState(Qt::Unchecked);
#else
setText(row, CI_Name, "");
setText(row, CI_Command, "");
Q3TableItem* ti = item(row, CI_Confirm);
Q3CheckTableItem* cti = dynamic_cast<Q3CheckTableItem*>(ti);
QTableItem* ti = item(row, CI_Confirm);
QCheckTableItem* cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
cti->setChecked(false);
}
ti = item(row, CI_Output);
cti = dynamic_cast<Q3CheckTableItem*>(ti);
cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
cti->setChecked(false);
}
#endif
}
/**
* Execute a context menu action.
*
* @param action action of selected menu
*/
#if QT_VERSION >= 0x040000
void CommandsTable::executeAction(QAction* action)
{
if (action) {
int row = action->data().toInt();
int cmd = row & 3;
row >>= 2;
switch (cmd) {
case 0:
addRow(row);
break;
case 1:
deleteRow(row);
break;
case 2:
default:
clearRow(row);
break;
}
}
}
#else
void CommandsTable::executeAction(QAction*) {}
#endif
/**
* Display context menu.
......@@ -127,10 +234,26 @@ void CommandsTable::clearRow(int row)
*/
void CommandsTable::contextMenu(int row, int /* col */, const QPoint& pos)
{
Q3PopupMenu menu(this);
#if QT_VERSION >= 0x040000
QMenu menu(this);
QAction* action;
if (row >= -1) {
action = menu.addAction(i18n("&Insert row"));
if (action) action->setData((row << 2) | 0);
}
if (row >= 0) {
action = menu.addAction(i18n("&Delete row"));
if (action) action->setData((row << 2) | 1);
}
if (row >= 0) {
action = menu.addAction(i18n("&Clear row"));
if (action) action->setData((row << 2) | 2);
}
connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(executeAction(QAction*)));
#else
QPopupMenu menu(this);
if (row >= -1) {
menu.insertItem(i18n("&Insert row"), this, SLOT(insertRow(int)), 0, 0);
menu.insertItem(i18n("&Insert row"), this, SLOT(addRow(int)), 0, 0);
menu.setItemParameter(0, row);
}
if (row >= 0) {
......@@ -141,30 +264,86 @@ void CommandsTable::contextMenu(int row, int /* col */, const QPoint& pos)
menu.insertItem(i18n("&Clear row"), this, SLOT(clearRow(int)), 0, 2);
menu.setItemParameter(2, row);
}
#endif
menu.setMouseTracking(true);
menu.exec(pos);
}
#if QT_VERSION >= 0x040000
/**
* Display custom context menu.
*
* @param pos position where context menu is drawn on screen
*/
void CommandsTable::customContextMenu(const QPoint& pos)
{
QTableWidgetItem* item = itemAt(pos);
if (item) {
#if QT_VERSION >= 0x040200
contextMenu(item->row(), item->column(), mapToGlobal(pos));
#else
contextMenu(currentRow(), currentColumn(), mapToGlobal(pos));
#endif
}
}
#else
void CommandsTable::customContextMenu(const QPoint&) {}
#endif
/**
* Set the table from the command list.
*
* @param cmdList command list
*/
void CommandsTable::setCommandList(const Q3ValueList<MiscConfig::MenuCommand>& cmdList)
void CommandsTable::setCommandList(const MiscConfig::MenuCommandList& cmdList)
{
#if QT_VERSION >= 0x040000
setRowCount(0);
int row = 0;
for (MiscConfig::MenuCommandList::const_iterator it = cmdList.begin();
it != cmdList.end();
++it) {
if (!(*it).getCommand().isEmpty()) {
insertRow(row);
QTableWidgetItem* cti = new QTableWidgetItem;
if (cti) {
cti->setCheckState((*it).mustBeConfirmed() ? Qt::Checked : Qt::Unchecked);
setItem(row, CI_Confirm, cti);
}
cti = new QTableWidgetItem;
if (cti) {
cti->setCheckState((*it).outputShown() ? Qt::Checked : Qt::Unchecked);
setItem(row, CI_Output, cti);
}
cti = new QTableWidgetItem((*it).getName());
if (cti) {
setItem(row, CI_Name, cti);
}
cti = new QTableWidgetItem((*it).getCommand());
if (cti) {
setItem(row, CI_Command, cti);
}
++row;
}
}
if (row == 0) {
// no commands => show at least one row
addRow(-1);
}
#else
setNumRows(0);
int row = 0;
for (Q3ValueList<MiscConfig::MenuCommand>::const_iterator it = cmdList.begin();
for (MiscConfig::MenuCommandList::const_iterator it = cmdList.begin();
it != cmdList.end();
++it) {
if (!(*it).getCommand().isEmpty()) {
insertRows(row);
Q3CheckTableItem* cti = new Q3CheckTableItem(this, "");
QCheckTableItem* cti = new QCheckTableItem(this, "");
if (cti) {
cti->setChecked((*it).mustBeConfirmed());
setItem(row, CI_Confirm, cti);
}
cti = new Q3CheckTableItem(this, "");
cti = new QCheckTableItem(this, "");
if (cti) {
cti->setChecked((*it).outputShown());
setItem(row, CI_Output, cti);
......@@ -176,8 +355,9 @@ void CommandsTable::setCommandList(const Q3ValueList<MiscConfig::MenuCommand>& c
}
if (row == 0) {
// no commands => show at least one row
insertRow(-1);
addRow(-1);
}
#endif
}
/**
......@@ -185,8 +365,37 @@ void CommandsTable::setCommandList(const Q3ValueList<MiscConfig::MenuCommand>& c
*
* @param cmdList the command list is returned here
*/
void CommandsTable::getCommandList(Q3ValueList<MiscConfig::MenuCommand>& cmdList) const
void CommandsTable::getCommandList(MiscConfig::MenuCommandList& cmdList) const
{
#if QT_VERSION >= 0x040000
cmdList.clear();
int nrRows = rowCount();
for (int row = 0; row < nrRows; ++row) {
QTableWidgetItem* twi = item(row, CI_Command);
if (twi) {
QString cmd = twi->text();
if (!cmd.isEmpty()) {
twi = item(row, CI_Name);
QString name;
if (twi) name = twi->text();
if (name.isEmpty()) {
name = cmd;
}
bool confirm = false;
bool showOutput = false;
twi = item(row, CI_Confirm);
if (twi && twi->checkState() == Qt::Checked) {
confirm = true;
}
twi = item(row, CI_Output);
if (twi && twi->checkState() == Qt::Checked) {
showOutput = true;
}
cmdList.push_back(MiscConfig::MenuCommand(name, cmd, confirm, showOutput));
}
}
}
#else
cmdList.clear();
int nrRows = numRows();
for (int row = 0; row < nrRows; ++row) {
......@@ -198,15 +407,15 @@ void CommandsTable::getCommandList(Q3ValueList<MiscConfig::MenuCommand>& cmdList
}
bool confirm = false;
bool showOutput = false;
Q3TableItem* ti = item(row, CI_Confirm);
Q3CheckTableItem* cti = dynamic_cast<Q3CheckTableItem*>(ti);
QTableItem* ti = item(row, CI_Confirm);
QCheckTableItem* cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
if (cti->isChecked()) {
confirm = true;
}
}
ti = item(row, CI_Output);
cti = dynamic_cast<Q3CheckTableItem*>(ti);
cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
if (cti->isChecked()) {
showOutput = true;
......@@ -215,4 +424,5 @@ void CommandsTable::getCommandList(Q3ValueList<MiscConfig::MenuCommand>& cmdList
cmdList.push_back(MiscConfig::MenuCommand(name, cmd, confirm, showOutput));
}
}
#endif
}
......@@ -12,16 +12,19 @@
#include "qtcompatmac.h"
#if QT_VERSION >= 0x040000
#include <Q3Table>
#include <QTableWidget>
typedef QTableWidget CommandsTableBaseClass;
#else
#include <qtable.h>
typedef QTable CommandsTableBaseClass;
class QAction;
#endif
#include "miscconfig.h"
/**
* Context menu commands configuration table.
*/
class CommandsTable : public Q3Table {
class CommandsTable : public CommandsTableBaseClass {
Q_OBJECT
public:
......@@ -29,9 +32,8 @@ public:
* Constructor.
*
* @param parent parent widget
* @param name Qt object name
*/
CommandsTable(QWidget* parent = 0, const char* name = 0);
CommandsTable(QWidget* parent = 0);
/**
* Destructor.
......@@ -43,14 +45,14 @@ public:
*
* @param cmdList command list
*/
void setCommandList(const Q3ValueList<MiscConfig::MenuCommand>& cmdList);
void setCommandList(const MiscConfig::MenuCommandList& cmdList);
/**
* Get the command list from the table.
*
* @param cmdList the command list is returned here
*/
void getCommandList(Q3ValueList<MiscConfig::MenuCommand>& cmdList) const;
void getCommandList(MiscConfig::MenuCommandList& cmdList) const;
public slots:
/**
......@@ -69,7 +71,7 @@ public slots:
*
* @param row the new row is inserted after this row
*/
void insertRow(int row);
void addRow(int row);
/**
* Delete a row from the table.
......@@ -85,6 +87,13 @@ public slots:
*/
void clearRow(int row);
/**
* Execute a context menu action.
*
* @param action action of selected menu
*/
void executeAction(QAction* action);
/**
* Display context menu.
*
......@@ -93,6 +102,13 @@ public slots:
* @param pos position where context menu is drawn on screen
*/
void contextMenu(int row, int col, const QPoint& pos);
/**
* Display custom context menu.
*
* @param pos position where context menu is drawn on screen
*/
void customContextMenu(const QPoint& pos);
};
#endif // COMMANDSTABLE_H
......@@ -20,11 +20,12 @@
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlineedit.h>
#include <qtabwidget.h>
#include "qtcompatmac.h"
#if QT_VERSION >= 0x040000
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <Q3GroupBox>
#include <QGroupBox>
#else
#include <qgroupbox.h>
#endif
......@@ -49,50 +50,78 @@ ConfigDialog::ConfigDialog(QWidget* parent, QString& caption,
IconList, Ok | Cancel | Help, Ok, true)
#else
ConfigDialog::ConfigDialog(QWidget* parent, QString& caption) :
Q3TabDialog(parent, "configure", true)
QDialog(parent)
#endif
{
setCaption(caption);
QCM_setWindowTitle(caption);
QVBoxLayout* vlayout = new QVBoxLayout(this);
vlayout->setSpacing(6);
vlayout->setMargin(6);
#ifndef KID3_USE_KCONFIGDIALOG
QTabWidget* tabWidget = new QTabWidget(this);
#endif
QWidget* tagsPage = new QWidget;
if (tagsPage) {
QVBoxLayout* vlayout = new QVBoxLayout(tagsPage, 6, 6);
QVBoxLayout* vlayout = new QVBoxLayout(tagsPage);
if (vlayout) {
Q3GroupBox* v1GroupBox = new Q3GroupBox(1, Qt::Horizontal, i18n("ID3v1"), tagsPage);
if (v1GroupBox) {
vlayout->setMargin(6);
vlayout->setSpacing(6);
#if QT_VERSION >= 0x040000
v1GroupBox->setInsideMargin(5);
QGroupBox* v1GroupBox = new QGroupBox(i18n("ID3v1"), tagsPage);
#else
QGroupBox* v1GroupBox = new QGroupBox(1, Qt::Horizontal, i18n("ID3v1"), tagsPage);
#endif
if (v1GroupBox) {
m_markTruncationsCheckBox = new QCheckBox(i18n("&Mark truncated fields"), v1GroupBox);
#if QT_VERSION >= 0x040000
QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(2);
hbox->addWidget(m_markTruncationsCheckBox);
v1GroupBox->setLayout(hbox);
#endif
vlayout->addWidget(v1GroupBox);
}
Q3GroupBox* v2GroupBox = new Q3GroupBox(1, Qt::Horizontal, i18n("ID3v2"), tagsPage);
if (v2GroupBox) {
#if QT_VERSION >= 0x040000
v2GroupBox->setInsideMargin(5);
QGroupBox* v2GroupBox = new QGroupBox(i18n("ID3v2"), tagsPage);
#else
QGroupBox* v2GroupBox = new QGroupBox(1, Qt::Horizontal, i18n("ID3v2"), tagsPage);
#endif
if (v2GroupBox) {
m_totalNumTracksCheckBox = new QCheckBox(i18n("Use &track/total number of tracks format"), v2GroupBox);
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
QLabel* id3v2VersionLabel = new QLabel(i18n("&Version used for new tags:"), v2GroupBox);
m_id3v2VersionComboBox = new QComboBox(v2GroupBox);
if (id3v2VersionLabel && m_id3v2VersionComboBox) {
m_id3v2VersionComboBox->insertItem(i18n("ID3v2.3.0 (id3lib)"), MiscConfig::ID3v2_3_0);
m_id3v2VersionComboBox->insertItem(i18n("ID3v2.4.0 (TagLib)"), MiscConfig::ID3v2_4_0);
m_id3v2VersionComboBox->QCM_insertItem(MiscConfig::ID3v2_3_0, i18n("ID3v2.3.0 (id3lib)"));
m_id3v2VersionComboBox->QCM_insertItem(MiscConfig::ID3v2_4_0, i18n("ID3v2.4.0 (TagLib)"));
m_id3v2VersionComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
id3v2VersionLabel->setBuddy(m_id3v2VersionComboBox);
}
#endif
#if QT_VERSION >= 0x040000
QVBoxLayout* vbox = new QVBoxLayout;
vbox->setMargin(2);
vbox->addWidget(m_totalNumTracksCheckBox);
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
vbox->addWidget(id3v2VersionLabel);
vbox->addWidget(m_id3v2VersionComboBox);
#endif
v2GroupBox->setLayout(vbox);
#endif
vlayout->addWidget(v2GroupBox);
}
#ifdef HAVE_VORBIS
Q3GroupBox* vorbisGroupBox = new Q3GroupBox(2, Qt::Horizontal, i18n("Ogg/Vorbis"), tagsPage);
if (vorbisGroupBox) {
#if QT_VERSION >= 0x040000
vorbisGroupBox->setInsideMargin(5);
QGroupBox* vorbisGroupBox = new QGroupBox(i18n("Ogg/Vorbis"), tagsPage);
#else
QGroupBox* vorbisGroupBox = new QGroupBox(2, Qt::Horizontal, i18n("Ogg/Vorbis"), tagsPage);
#endif
if (vorbisGroupBox) {
QLabel* commentNameLabel = new QLabel(i18n("Comment field &name:"), vorbisGroupBox);
m_commentNameComboBox = new QComboBox(true, vorbisGroupBox);
m_commentNameComboBox = new QComboBox(vorbisGroupBox);
if (commentNameLabel && m_commentNameComboBox) {
m_commentNameComboBox->setEditable(true);
QStringList items;
items += "COMMENT";
items += "DESCRIPTION";
......@@ -100,48 +129,73 @@ ConfigDialog::ConfigDialog(QWidget* parent, QString& caption) :
m_commentNameComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
commentNameLabel->setBuddy(m_commentNameComboBox);
}
#if QT_VERSION >= 0x040000
QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(2);
hbox->addWidget(commentNameLabel);
hbox->addWidget(m_commentNameComboBox);
vorbisGroupBox->setLayout(hbox);
#endif
vlayout->addWidget(vorbisGroupBox);
}
#endif
QHBoxLayout* hlayout = new QHBoxLayout(vlayout);
QHBoxLayout* hlayout = new QHBoxLayout;
if (hlayout) {
Q3GroupBox* genresGroupBox = new Q3GroupBox(1, Qt::Horizontal, i18n("Custom &Genres"), tagsPage);
if (genresGroupBox) {
#if QT_VERSION >= 0x040000
genresGroupBox->setInsideMargin(5);
QGroupBox* genresGroupBox = new QGroupBox(i18n("Custom &Genres"), tagsPage);
#else
QGroupBox* genresGroupBox = new QGroupBox(1, Qt::Horizontal, i18n("Custom &Genres"), tagsPage);
#endif
if (genresGroupBox) {
m_onlyCustomGenresCheckBox = new QCheckBox(i18n("&Show only custom genres"), genresGroupBox);
m_genresEdit = new StringListEdit(genresGroupBox, "genresList");