void TextEditWidget::sl_MergeCellsAction_Triggered() {
	QTextTable* table = textField->textCursor().currentTable();
	if (!table) {
		WARNING("Wrong button state");
		return;
	}

	table->mergeCells(textField->textCursor());
}
static PyObject *meth_QTextTable_mergeCells(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        int a0;
        int a1;
        int a2;
        int a3;
        QTextTable *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "Biiii", &sipSelf, sipType_QTextTable, &sipCpp, &a0, &a1, &a2, &a3))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->mergeCells(a0,a1,a2,a3);
            Py_END_ALLOW_THREADS

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    {
        const QTextCursor* a0;
        QTextTable *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QTextTable, &sipCpp, sipType_QTextCursor, &a0))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->mergeCells(*a0);
            Py_END_ALLOW_THREADS

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QTextTable, sipName_mergeCells, doc_QTextTable_mergeCells);

    return NULL;
}
Esempio n. 3
0
int main(int argc, char * argv[])
{
    int rows = 6;
    int columns = 2;

    QApplication app(argc, argv);
    QTextEdit *textEdit = new QTextEdit;
    QTextCursor cursor(textEdit->textCursor());
    cursor.movePosition(QTextCursor::Start);

    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignHCenter);
    tableFormat.setCellPadding(2);
    tableFormat.setCellSpacing(2);
    QTextTable *table = cursor.insertTable(rows, columns);
    table->setFormat(tableFormat);
    
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);

    QTextBlockFormat centerFormat;
    centerFormat.setAlignment(Qt::AlignHCenter);
    cursor.mergeBlockFormat(centerFormat);

    cursor = table->cellAt(0, 0).firstCursorPosition();
    cursor.insertText(("Details"), boldFormat);

    cursor = table->cellAt(1, 0).firstCursorPosition();
    cursor.insertText("Alan");

    cursor = table->cellAt(1, 1).firstCursorPosition();
    cursor.insertText("5, Pickety Street");

//! [0]
    table->mergeCells(0, 0, 1, 2);
//! [0] //! [1]
    table->splitCell(0, 0, 1, 1);
//! [1]

    textEdit->show();
    return app.exec();
}
Esempio n. 4
0
bool PriceListPrinter::printODT( PriceListPrinter::PrintPriceItemsOption printOption,
                                 const QList<int> &fieldsToPrint,
                                 int priceDataSetToPrintInput,
                                 bool printPriceList,
                                 bool printPriceAP,
                                 bool APgroupPrAm,
                                 const QString &fileName,
                                 double pageWidth,
                                 double pageHeight,
                                 Qt::Orientation paperOrientation) {
    double borderWidth = 1.0f;
    if( m_d->priceList ){
        int priceDataSetToPrint = 0;
        // controlliamo se il valore di input è corretto
        if( priceDataSetToPrintInput >= 0 && priceDataSetToPrintInput < m_d->priceList->priceDataSetCount() ){
            priceDataSetToPrint = priceDataSetToPrintInput;
        }

        QTextDocument doc;
        QTextCursor cursor(&doc);

        if( paperOrientation == Qt::Horizontal ){
            if( pageHeight > pageWidth ){
                double com = pageHeight;
                pageHeight = pageWidth;
                pageWidth = com;
            }
        } else {
            if( pageHeight < pageWidth ){
                double com = pageHeight;
                pageHeight = pageWidth;
                pageWidth = com;
            }
        }
        double margin = 10.0;
        double tableWidth =  pageWidth - 2.0 * margin;

        QTextCharFormat headerBlockCharFormat;
        headerBlockCharFormat.setFontCapitalization( QFont::AllUppercase );
        headerBlockCharFormat.setFontWeight( QFont::Bold );

        QTextBlockFormat headerBlockFormat;
        headerBlockFormat.setAlignment( Qt::AlignHCenter );

        QTextBlockFormat headerWithPBBlockFormat = headerBlockFormat;
        headerWithPBBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );

        QTextBlockFormat parBlockFormat;

        if( printPriceList ){
            cursor.setBlockFormat( headerWithPBBlockFormat );
            cursor.setBlockCharFormat( headerBlockCharFormat );
            cursor.insertText( m_d->priceList->name() );

            cursor.insertBlock( headerBlockFormat );
            cursor.setBlockCharFormat( headerBlockCharFormat );
            cursor.insertText(QObject::trUtf8("Elenco Prezzi") );

            cursor.insertBlock( parBlockFormat );

            QTextTableFormat tableFormat;
            tableFormat.setCellPadding(5);
            tableFormat.setHeaderRowCount(2);
            tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
            tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
            QVector<QTextLength> colWidths;
            if( paperOrientation == Qt::Horizontal ){
                double descColWidth = tableWidth - ( 30.0 + 20.0 + 35.0 * fieldsToPrint.size() );
                colWidths << QTextLength( QTextLength::FixedLength, 30.0 )
                          << QTextLength( QTextLength::FixedLength, descColWidth )
                          << QTextLength( QTextLength::FixedLength, 20.0 );
                for( int i=0; i < fieldsToPrint.size(); ++i ){
                    colWidths << QTextLength( QTextLength::FixedLength, 35.0 );
                }
            } else {
                double descColWidth = tableWidth - ( 25.0 + 15.0 + 30.0 * fieldsToPrint.size() );
                colWidths << QTextLength( QTextLength::FixedLength, 25.0 )
                          << QTextLength( QTextLength::FixedLength, descColWidth )
                          << QTextLength( QTextLength::FixedLength, 15.0 );
                for( int i=0; i < fieldsToPrint.size(); ++i ){
                    colWidths << QTextLength( QTextLength::FixedLength, 30.0 );
                }
            }
            tableFormat.setColumnWidthConstraints( colWidths );
            tableFormat.setHeaderRowCount( 2 );
            cursor.insertTable(1, colWidths.size(), tableFormat);

            m_d->priceList->writeODTOnTable( &cursor, printOption, fieldsToPrint, priceDataSetToPrint );

            cursor.movePosition( QTextCursor::End );
        }

        if( printPriceAP ){
            bool firstAP=true;

            QList<PriceItem *> priceItemList = m_d->priceList->priceItemList();
            for( int i=0; i < priceItemList.size(); ++i ){
                if( (!priceItemList.at(i)->hasChildren()) && (priceItemList.at(i)->associateAP(priceDataSetToPrint)) ){
                    if( firstAP ){
                        if( printPriceList ){
                            // abbiamo stampato già l'elenco prezzi
                            cursor.insertBlock( headerWithPBBlockFormat );
                        } else { //  printData == DataAP
                            // non abbiamo stampato l'elenco prezzi
                            cursor.setBlockFormat( headerWithPBBlockFormat );
                        }
                        cursor.setBlockCharFormat( headerBlockCharFormat );
                        cursor.insertText( m_d->priceList->name() );

                        cursor.insertBlock( headerBlockFormat );
                        cursor.setBlockCharFormat( headerBlockCharFormat );
                        cursor.insertText(QObject::trUtf8("Analisi Prezzi") );

                        cursor.insertBlock( parBlockFormat );

                        firstAP = false;
                    } else {
                        cursor.insertBlock( headerWithPBBlockFormat );
                        cursor.insertText( QString() );
                        cursor.insertBlock( parBlockFormat );
                    }

                    QTextTableCellFormat topLeftFormat;
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) );
                    QTextTableCellFormat topRightFormat;
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) );
                    QTextTableCellFormat bottomFormat;
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomWidth, QVariant(borderWidth) );

                    // tabella con informazioni generali sul prezzo
                    // descrizione, codice, etc
                    QTextTableFormat tableFormat;
                    tableFormat.setCellPadding(5);
                    tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
                    tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
                    QVector<QTextLength> colWidths;
                    colWidths << QTextLength( QTextLength::FixedLength, 25 )
                              << QTextLength( QTextLength::FixedLength, pageWidth-2.0*margin - 25 );
                    tableFormat.setColumnWidthConstraints( colWidths );
                    QTextTable * table = cursor.insertTable(1, colWidths.size(), tableFormat);

                    table->cellAt( cursor ).setFormat( topLeftFormat );
                    cursor.insertText( priceItemList.at(i)->codeFull() );

                    cursor.movePosition(QTextCursor::NextCell);
                    table->cellAt( cursor ).setFormat( topRightFormat );
                    cursor.insertText( priceItemList.at(i)->shortDescriptionFull() );

                    table->appendRows(1);
                    table->mergeCells( 1, 0, 1, 2 );
                    cursor.movePosition(QTextCursor::PreviousRow );
                    cursor.movePosition(QTextCursor::NextCell );
                    table->cellAt( cursor ).setFormat( bottomFormat );
                    cursor.insertText( priceItemList.at(i)->longDescriptionFull() );
                    cursor.movePosition( QTextCursor::End );

                    // tabella con l'analisi prezzi vera e propria
                    tableFormat.setCellPadding(5);
                    tableFormat.setHeaderRowCount(2);
                    tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
                    tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
                    colWidths.clear();
                    if( paperOrientation == Qt::Horizontal ){
                        if( fieldsToPrint.size() > 0 ){
                            colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                      << QTextLength( QTextLength::FixedLength, 30.0 )
                                      << QTextLength( QTextLength::FixedLength, 70.0 )
                                      << QTextLength( QTextLength::FixedLength, 20.0 );
                            double usedWidth =  10.0 + 30.0 + 70.0 + 20.0;
                            double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() );
                            for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){
                                colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth );
                            }
                        } else { // fieldsToPrint.size() == 0
                            if( fieldsToPrint.size() > 1  ){
                                double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0);
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 )
                                          << QTextLength( QTextLength::FixedLength, descWidth )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 );
                            }
                        }
                    } else {
                        if( fieldsToPrint.size() > 0 ){
                            double usedWidth = 0.0;
                            if( fieldsToPrint.size() > 1  ){
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 45.0 )
                                          << QTextLength( QTextLength::FixedLength, 15.0 );
                                usedWidth =  10.0 + 20.0 + 45.0 + 15.0;
                            } else { // fieldsToPrint.size() == 1
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 25.0 )
                                          << QTextLength( QTextLength::FixedLength, 65.0 )
                                          << QTextLength( QTextLength::FixedLength, 15.0 );
                                usedWidth =  10.0 + 25.0 + 65.0 + 15.0;
                            }
                            double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() );
                            for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){
                                colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth );
                            }
                        } else { // fieldsToPrint.size() == 0
                            if( fieldsToPrint.size() > 1  ){
                                double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0);
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 )
                                          << QTextLength( QTextLength::FixedLength, descWidth )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 );
                            }
                        }
                    }
                    tableFormat.setColumnWidthConstraints( colWidths );
                    tableFormat.setHeaderRowCount( 2 );
                    cursor.insertTable(1, colWidths.size(), tableFormat);

                    BillPrinter::PrintBillItemsOption billPrItemsOption = BillPrinter::PrintShortDesc;
                    if( printOption == PriceListPrinter::PrintShortDesc ){
                        billPrItemsOption = BillPrinter::PrintShortDesc;
                    } else if( printOption == PriceListPrinter::PrintLongDesc ){
                        billPrItemsOption = BillPrinter::PrintLongDesc;
                    } else if( printOption == PriceListPrinter::PrintShortLongDesc ){
                        billPrItemsOption = BillPrinter::PrintShortLongDesc;
                    } else if( printOption == PriceListPrinter::PrintShortLongDescOpt ){
                        billPrItemsOption = BillPrinter::PrintShortLongDescOpt;
                    }
                    priceItemList.at(i)->associatedAP(priceDataSetToPrint)->writeODTBillOnTable( &cursor, billPrItemsOption, fieldsToPrint, APgroupPrAm );

                    cursor.movePosition( QTextCursor::End );
                }

            }
        }

        QFile *file = new QFile(fileName);
        QString suf = QFileInfo(file->fileName()).suffix().toLower().toLatin1();
        if (suf == "odf" || suf == "opendocumentformat" || suf == "odt") {
            OdtWriter writer(doc, file);
            writer.setPageSizeMM( pageWidth, pageHeight );
            writer.setMarginsMM( margin, margin, margin, margin );
            writer.setPageOrientation( paperOrientation );
            // writer.setCodec(codec);
            return writer.writeAll();
        }
    }
    return false;
}
Esempio n. 5
0
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
    QDialog(parent),
    ui(new Ui::HelpMessageDialog)
{
    ui->setupUi(this);
    GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);

    QString version = tr("Unobtanium Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
    /* On x86 add a bit specifier to the version so that users can distinguish between
     * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
     */
#if defined(__x86_64__)
    version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
    version += " " + tr("(%1-bit)").arg(32);
#endif

    if (about)
    {
        setWindowTitle(tr("About Unobtanium Core"));

        /// HTML-format the license message from the core
        QString licenseInfo = QString::fromStdString(LicenseInfo());
        QString licenseInfoHTML = licenseInfo;
        // Make URLs clickable
        QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
        uri.setMinimal(true); // use non-greedy matching
        licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
        // Replace newlines with HTML breaks
        licenseInfoHTML.replace("\n\n", "<br><br>");

        ui->aboutMessage->setTextFormat(Qt::RichText);
        ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        text = version + "\n" + licenseInfo;
        ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
        ui->aboutMessage->setWordWrap(true);
        ui->helpMessage->setVisible(false);
    } else {
        setWindowTitle(tr("Command-line options"));
        QTextCursor cursor(ui->helpMessage->document());
        cursor.insertText(version);
        cursor.insertBlock();
        cursor.insertText(tr("Usage:") + '\n' +
            "  bitcoin-qt [" + tr("command-line options") + "]\n");

        cursor.insertBlock();
        QTextTableFormat tf;
        tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
        tf.setCellPadding(2);
        QVector<QTextLength> widths;
        widths << QTextLength(QTextLength::PercentageLength, 35);
        widths << QTextLength(QTextLength::PercentageLength, 65);
        tf.setColumnWidthConstraints(widths);
        QTextTable *table = cursor.insertTable(2, 2, tf);

        QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
        bool first = true;
        QTextCharFormat bold;
        bold.setFontWeight(QFont::Bold);
        // note that coreOptions is not translated.
        foreach (const QString &line, coreOptions.split('\n')) {
            if (!first) {
                table->appendRows(1);
                cursor.movePosition(QTextCursor::NextRow);
            }
            first = false;

            if (line.startsWith("  ")) {
                int index = line.indexOf(' ', 3);
                if (index > 0) {
                    cursor.insertText(line.left(index).trimmed());
                    cursor.movePosition(QTextCursor::NextCell);
                    cursor.insertText(line.mid(index).trimmed());
                    continue;
                }
            }
            cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor);
            table->mergeCells(cursor);
            cursor.insertText(line.trimmed(), bold);
        }

        table->appendRows(6);
        cursor.movePosition(QTextCursor::NextRow);
        cursor.insertText(tr("UI options") + ":", bold);
        cursor.movePosition(QTextCursor::NextRow);
        if (GetBoolArg("-help-debug", false)) {
            cursor.insertText("-allowselfsignedrootcertificates");
            cursor.movePosition(QTextCursor::NextCell);
            cursor.insertText(tr("Allow self signed root certificates (default: 0)"));
            cursor.movePosition(QTextCursor::NextCell);
        }
        cursor.insertText("-choosedatadir");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Choose data directory on startup (default: 0)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-lang=<lang>");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Set language, for example \"de_DE\" (default: system locale)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-min");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Start minimized"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-rootcertificates=<file>");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Set SSL root certificates for payment request (default: -system-)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-splash");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Show splash screen on startup (default: 1)"));

        ui->helpMessage->moveCursor(QTextCursor::Start);
        ui->scrollArea->setVisible(false);
        ui->aboutLogo->setVisible(false);
    }
}
Esempio n. 6
0
void DetailsTable::createRSTTAble(SkyObject *obj, const KStarsDateTime &ut, GeoLocation *geo)
{
    clearContents();

    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();

    QString rtValue, stValue; // Rise/Set time values
    QString azRValue, azSValue; // Rise/Set azimuth values

    //Prepare time/position variables
    QTime rt = obj->riseSetTime(ut, geo, true); //true = use rise time
    dms raz = obj->riseSetTimeAz(ut, geo, true); //true = use rise time

    //If transit time is before rise time, use transit time for tomorrow
    QTime tt = obj->transitTime(ut, geo);
    dms talt = obj->transitAltitude(ut, geo);
    if(tt < rt)
    {
        tt = obj->transitTime(ut.addDays(1), geo);
        talt = obj->transitAltitude(ut.addDays(1), geo);
    }

    //If set time is before rise time, use set time for tomorrow
    QTime st = obj->riseSetTime(ut, geo, false); //false = use set time
    dms saz = obj->riseSetTimeAz(ut, geo, false); //false = use set time
    if(st < rt)
    {
        st = obj->riseSetTime(ut.addDays(1), geo, false); //false = use set time
        saz = obj->riseSetTimeAz(ut.addDays( 1 ), geo, false); //false = use set time
    }

    if(rt.isValid())
    {
        rtValue = QString().sprintf("%02d:%02d", rt.hour(), rt.minute());
        stValue = QString().sprintf("%02d:%02d", st.hour(), st.minute());
        azRValue = raz.toDMSString();
        azSValue = saz.toDMSString();
    }

    else
    {
        if(obj->alt().Degrees() > 0.0)
        {
            rtValue = i18n("Circumpolar");
            stValue = i18n("Circumpolar");
        }

        else
        {
            rtValue = i18n("Never rises");
            stValue = i18n("Never rises");
        }

        azRValue = i18nc("Not Applicable", "N/A");
        azSValue = i18nc("Not Applicable", "N/A");
    }

    // Set column width constraints
    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25);
    m_TableFormat.setColumnWidthConstraints(constraints);

    // Insert table & row containing table name
    QTextTable *table = cursor.insertTable(4, 4, m_TableFormat);
    table->mergeCells(0, 0, 1, 4);
    QTextBlockFormat centered;
    centered.setAlignment(Qt::AlignCenter);
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Rise/Set/Transit"), m_TableTitleCharFormat);

    // Insert cell names & values
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Rise time:"), m_ItemNameCharFormat);
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 1).firstCursorPosition().insertText(rtValue, m_ItemValueCharFormat);

    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Transit time:"), m_ItemNameCharFormat);
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 1).firstCursorPosition().insertText(QString().sprintf("%02d:%02d", tt.hour(), tt.minute()), m_ItemValueCharFormat);

    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Set time:"), m_ItemNameCharFormat);
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 1).firstCursorPosition().insertText(stValue, m_ItemValueCharFormat);

    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Azimuth at rise:"), m_ItemNameCharFormat);
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 3).firstCursorPosition().insertText(azRValue, m_ItemValueCharFormat);

    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Altitude at transit:"), m_ItemNameCharFormat);
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 3).firstCursorPosition().insertText(talt.toDMSString(), m_ItemValueCharFormat);

    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Azimuth at set:"), m_ItemNameCharFormat);
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 3).firstCursorPosition().insertText(azSValue, m_ItemValueCharFormat);

    // Restore the position and other time-dependent parameters
    obj->recomputeCoords( ut, geo );
}
Esempio n. 7
0
void DetailsTable::createCoordinatesTable(SkyObject *obj, const KStarsDateTime &ut, GeoLocation *geo)
{
    clearContents();

    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();

    // Set column width constraints
    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25);
    m_TableFormat.setColumnWidthConstraints(constraints);

    // Insert table & row containing table name
    QTextTable *table = cursor.insertTable(4, 4, m_TableFormat);
    table->mergeCells(0, 0, 1, 4);
    QTextBlockFormat centered;
    centered.setAlignment(Qt::AlignCenter);
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Coordinates"), m_TableTitleCharFormat);

    //Coordinates Section:
    //Don't use KLocale::formatNumber() for the epoch string,
    //because we don't want a thousands-place separator!
    QString sEpoch = QString::number(ut.epoch(), 'f', 1);
    //Replace the decimal point with localized decimal symbol
    sEpoch.replace('.', KGlobal::locale()->decimalSymbol());

    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("RA (%1):", sEpoch), m_ItemNameCharFormat);
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 1).firstCursorPosition().insertText(obj->ra().toHMSString(), m_ItemValueCharFormat);

    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Dec (%1):", sEpoch), m_ItemNameCharFormat);
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 1).firstCursorPosition().insertText(obj->dec().toDMSString(), m_ItemValueCharFormat);

    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Hour angle:"), m_ItemNameCharFormat);
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
    //Hour Angle can be negative, but dms HMS expressions cannot.
    //Here's a kludgy workaround:
    dms lst = geo->GSTtoLST(ut.gst());
    dms ha(lst.Degrees() - obj->ra().Degrees());
    QChar sgn('+');
    if(ha.Hours() > 12.0)
    {
        ha.setH(24.0 - ha.Hours());
        sgn = '-';
    }
    table->cellAt(3, 1).firstCursorPosition().insertText(QString("%1%2").arg(sgn).arg(ha.toHMSString()), m_ItemValueCharFormat);

    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Azimuth:"), m_ItemNameCharFormat);
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 3).firstCursorPosition().insertText(obj->az().toDMSString(), m_ItemValueCharFormat);

    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Altitude:"), m_ItemNameCharFormat);
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
    dms a;
    if(Options::useAltAz())
    {
        a = obj->alt();
    }

    else
    {
        a = obj->altRefracted();
    }
    table->cellAt(2, 3).firstCursorPosition().insertText(a.toDMSString(), m_ItemValueCharFormat);

    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Airmass:"), m_ItemNameCharFormat);
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
    //Airmass is approximated as the secant of the zenith distance,
    //equivalent to 1./sin(Alt).  Beware of Inf at Alt=0!
    QString aMassStr;
    if(obj->alt().Degrees() > 0.0)
    {
        aMassStr = KGlobal::locale()->formatNumber(1./sin(obj->alt().radians() ), 2);
    }

    else
    {
        aMassStr = "--";
    }
    table->cellAt(3, 3).firstCursorPosition().insertText(aMassStr, m_ItemValueCharFormat);

    // Restore the position and other time-dependent parameters
    obj->recomputeCoords(ut, geo);
}
Esempio n. 8
0
void DetailsTable::createGeneralTable(SkyObject *obj)
{
    clearContents();

    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();

    //Fill in the data fields
    //Contents depend on type of object
    StarObject *s = 0;
    DeepSkyObject *dso = 0;
    KSPlanetBase *ps = 0;
    QString pname, oname;

    QString objNamesVal, objTypeVal, objDistVal, objSizeVal, objMagVal, objBvVal, objIllumVal;
    QString objSizeLabel, objMagLabel;

    switch(obj->type())
    {
    case SkyObject::STAR:
        {
            s = (StarObject *)obj;

            objNamesVal = s->longname();

            if(s->getHDIndex() != 0)
            {
                if(!s->longname().isEmpty())
                {
                    objNamesVal = s->longname() + QString(", HD%1").arg(QString::number(s->getHDIndex())) ;
                }

                else
                {
                    objNamesVal = QString(", HD%1").arg(QString::number(s->getHDIndex()));
                }
            }

            objTypeVal = s->sptype() + ' ' + i18n("star");
            objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(s->mag(), 1)); //show to tenths place

            if(s->getBVIndex() < 30.0)
            {
                objBvVal = QString::number(s->getBVIndex(), 'g', 2);
            }

            //distance
            if(s->distance() > 2000. || s->distance() < 0.)  // parallax < 0.5 mas
            {
                objDistVal = i18nc("larger than 2000 parsecs", "> 2000 pc");
            }

            else if(s->distance() > 50.0) //show to nearest integer
            {
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 0));
            }

            else if(s->distance() > 10.0) //show to tenths place
            {
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 1));
            }

            else //show to hundredths place
            {
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 2));
            }

            //Note multiplicity/variablility in angular size label
            if(s->isMultiple() && s->isVariable())
            {
                objSizeLabel = i18nc("the star is a multiple star", "multiple") + ',';
                objSizeVal = i18nc("the star is a variable star", "variable");
            }

            else if(s->isMultiple())
            {
                objSizeLabel = i18nc("the star is a multiple star", "multiple");
            }

            else if(s->isVariable())
            {
                objSizeLabel = i18nc("the star is a variable star", "variable");
            }

            objIllumVal = "--";

            break; //End of stars case
        }

    case SkyObject::ASTEROID:  //[fall through to planets]

    case SkyObject::COMET:     //[fall through to planets]

    case SkyObject::MOON:      //[fall through to planets]

    case SkyObject::PLANET:
        {
            ps = (KSPlanetBase *)obj;

            objNamesVal = ps->longname();
            //Type is "G5 star" for Sun
            if(ps->name() == "Sun")
            {
                objTypeVal = i18n("G5 star");
            }

            else if(ps->name() == "Moon")
            {
                objTypeVal = ps->translatedName();
            }

            else if(ps->name() == i18n("Pluto") || ps->name() == "Ceres" || ps->name() == "Eris") // TODO: Check if Ceres / Eris have translations and i18n() them
            {
                objTypeVal = i18n("Dwarf planet");
            }

            else
            {
                objTypeVal = ps->typeName();
            }

            //Magnitude: The moon displays illumination fraction instead
            if(obj->name() == "Moon")
            {
                objIllumVal = QString("%1 %").arg(KGlobal::locale()->formatNumber(((KSMoon *)obj)->illum()*100., 0));
            }

            objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(ps->mag(), 1)); //show to tenths place

            //Distance from Earth.  The moon requires a unit conversion
            if(ps->name() == "Moon")
            {
                objDistVal = i18nc("distance in kilometers", "%1 km", KGlobal::locale()->formatNumber(ps->rearth() * AU_KM ));
            }

            else
            {
                objDistVal = i18nc("distance in Astronomical Units", "%1 AU", KGlobal::locale()->formatNumber(ps->rearth()));
            }

            //Angular size; moon and sun in arcmin, others in arcsec
            if(ps->angSize())
            {
                if(ps->name() == "Sun" || ps->name() == "Moon")
                {
                    // Needn't be a plural form because sun / moon will never contract to 1 arcminute
                    objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(ps->angSize()));
                }

                else
                {
                    objSizeVal = i18nc("angular size in arcseconds","%1 arcsec", KGlobal::locale()->formatNumber(ps->angSize() * 60.0));
                }
            }

            else
            {
                objSizeVal = "--";
            }

            break; //End of planets/comets/asteroids case
        }

    default: //Deep-sky objects
        {
            dso = (DeepSkyObject *)obj;

            //Show all names recorded for the object
            if(!dso->longname().isEmpty() && dso->longname() != dso->name())
            {
                pname = dso->translatedLongName();
                oname = dso->translatedName();
            }

            else
            {
                pname = dso->translatedName();
            }

            if(!dso->translatedName2().isEmpty())
            {
                if(oname.isEmpty())
                {
                    oname = dso->translatedName2();
                }

                else
                {
                    oname += ", " + dso->translatedName2();
                }
            }

            if(dso->ugc() != 0)
            {
                if(!oname.isEmpty())
                {
                    oname += ", ";
                }

                oname += "UGC " + QString::number(dso->ugc());
            }
            if(dso->pgc() != 0)
            {
                if(!oname.isEmpty())
                {
                    oname += ", ";
                }

                oname += "PGC " + QString::number(dso->pgc());
            }

            if(!oname.isEmpty())
            {
                pname += ", " + oname;
            }

            objNamesVal = pname;

            objTypeVal = dso->typeName();

            if(dso->type() == SkyObject::RADIO_SOURCE)
            {
                objMagLabel = i18nc("integrated flux at a frequency", "Flux(%1):", dso->customCatalog()->fluxFrequency());
                objMagVal = i18nc("integrated flux value", "%1 %2", KGlobal::locale()->formatNumber(dso->flux(), 1),
                                  dso->customCatalog()->fluxUnit()); //show to tenths place
            }

            else if(dso->mag() > 90.0)
            {
                objMagVal = "--";
            }

            else
            {
                objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(dso->mag(), 1)); //show to tenths place
            }

            //No distances at this point...
            objDistVal = "--";

            //Only show decimal place for small angular sizes
            if(dso->a() > 10.0)
            {
                objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 0));
            }

            else if(dso->a())
            {
                objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 1));
            }

            else
            {
                objSizeVal = "--";
            }

            break; //End of deep-space objects case
        }
    }

    //Common to all types:
    if(obj->type() == SkyObject::CONSTELLATION )
    {
        objTypeVal = KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj);
    }

    else
    {
        objTypeVal = i18nc("%1 type of sky object (planet, asteroid etc), %2 name of a constellation", "%1 in %2", objTypeVal,
                           KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj));
    }

    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25);
    m_TableFormat.setColumnWidthConstraints(constraints);

    QTextTable *table = cursor.insertTable(5, 4, m_TableFormat);
    table->mergeCells(0, 0, 1, 4);
    QTextBlockFormat centered;
    centered.setAlignment(Qt::AlignCenter);
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("General"), m_TableTitleCharFormat);

    table->mergeCells(1, 1, 1, 3);
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Names:"), m_ItemNameCharFormat);
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 1).firstCursorPosition().insertText(objNamesVal, m_ItemValueCharFormat);

    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Type:"), m_ItemNameCharFormat);
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 1).firstCursorPosition().insertText(objTypeVal, m_ItemValueCharFormat);

    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Distance:"), m_ItemNameCharFormat);
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 1).firstCursorPosition().insertText(objDistVal, m_ItemValueCharFormat);

    table->cellAt(4, 0).firstCursorPosition().insertText(i18n("Size:"), m_ItemNameCharFormat);
    table->cellAt(4, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(4, 1).firstCursorPosition().insertText(objSizeVal, m_ItemValueCharFormat);

    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Magnitude:"), m_ItemNameCharFormat);
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 3).firstCursorPosition().insertText(objMagVal, m_ItemValueCharFormat);

    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("B-V index:"), m_ItemNameCharFormat);
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 3).firstCursorPosition().insertText(objBvVal, m_ItemValueCharFormat);

    table->cellAt(4, 2).firstCursorPosition().insertText(i18n("Illumination:"), m_ItemNameCharFormat);
    table->cellAt(4, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(4, 3).firstCursorPosition().insertText(objIllumVal, m_ItemValueCharFormat);
}
Esempio n. 9
0
void DetailsTable::createAsteroidCometTable(SkyObject *obj)
{
    clearContents();

    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();

    QString perihelionVal, orbitIdVal, neoVal, diamVal, rotPeriodVal, moidVal;
    QString orbitClassVal, albedoVal, dimVal, periodVal;

    // Add specifics data
    switch(obj->type())
    {
    case SkyObject::ASTEROID:
        {
            KSAsteroid* ast = (KSAsteroid *)obj;

            // Perihelion
            perihelionVal = QString::number(ast->getPerihelion()) + " AU";

            // Earth MOID
            moidVal = ast->getEarthMOID() == 0 ? QString("--") : QString::number(ast->getEarthMOID()) + QString(" AU");

            // Orbit ID
            orbitIdVal = ast->getOrbitID();

            // Orbit Class
            orbitClassVal = ast->getOrbitClass();

            // NEO
            neoVal = ast->isNEO() ? i18n("Yes") : i18n("No");

            // Albedo
            albedoVal = ast->getAlbedo() == 0 ? QString("--") : QString::number(ast->getAlbedo());

            // Diameter
            diamVal = ast->getDiameter() == 0 ? QString("--") : QString::number(ast->getDiameter()) + QString(" km");

            // Dimensions
            dimVal = ast->getDimensions().isEmpty() ? QString("--") : ast->getDimensions() + QString(" km");

            // Rotation period
            rotPeriodVal = ast->getRotationPeriod() == 0 ? QString("--") : QString::number(ast->getRotationPeriod()) + QString(" h");

            // Period
            periodVal = ast->getPeriod() == 0 ? QString("--") : QString::number(ast->getPeriod()) + QString(" y");

            break;
        }

    case SkyObject::COMET:
        {
            KSComet* com = (KSComet *)obj;

            // Perihelion
            perihelionVal = QString::number(com->getPerihelion()) + " AU";

            // Earth MOID
            moidVal = com->getEarthMOID() == 0 ? QString("--") : QString::number(com->getEarthMOID()) + QString(" AU");

            // Orbit ID
            orbitIdVal = com->getOrbitID();

            // Orbit Class
            orbitClassVal = com->getOrbitClass();

            // NEO
            neoVal = com->isNEO() ? i18n("Yes") : i18n("No");

            // Albedo
            albedoVal = com->getAlbedo() == 0 ? QString("--") : QString::number(com->getAlbedo());

            // Diameter
            diamVal = com->getDiameter() == 0 ? QString("--") : QString::number(com->getDiameter()) + QString(" km");

            // Dimensions
            dimVal = com->getDimensions().isEmpty() ? QString("--") : com->getDimensions() + QString(" km");

            // Rotation period
            rotPeriodVal = com->getRotationPeriod() == 0 ? QString("--") : QString::number(com->getRotationPeriod()) + QString(" h");

            // Period
            periodVal = com->getPeriod() == 0 ? QString("--") : QString::number(com->getPeriod()) + QString(" y");

            break;
        }

    default:
        {
            return;
        }
    }

    // Set column width constraints
    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25)
                << QTextLength(QTextLength::PercentageLength, 25);
    m_TableFormat.setColumnWidthConstraints(constraints);

    QTextTable *table = cursor.insertTable(6, 4, m_TableFormat);
    table->mergeCells(0, 0, 1, 4);
    QTextBlockFormat centered;
    centered.setAlignment(Qt::AlignCenter);
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Asteroid/Comet details"), m_TableTitleCharFormat);

    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Perihelion:"), m_ItemNameCharFormat);
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 1).firstCursorPosition().insertText(perihelionVal, m_ItemValueCharFormat);

    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Orbit ID:"), m_ItemNameCharFormat);
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 1).firstCursorPosition().insertText(orbitIdVal, m_ItemValueCharFormat);

    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("NEO:"), m_ItemNameCharFormat);
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 1).firstCursorPosition().insertText(neoVal, m_ItemValueCharFormat);

    table->cellAt(4, 0).firstCursorPosition().insertText(i18n("Diameter:"), m_ItemNameCharFormat);
    table->cellAt(4, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(4, 1).firstCursorPosition().insertText(diamVal, m_ItemValueCharFormat);

    table->cellAt(5, 0).firstCursorPosition().insertText(i18n("Rotation period:"), m_ItemNameCharFormat);
    table->cellAt(5, 0).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(5, 1).firstCursorPosition().insertText(rotPeriodVal, m_ItemValueCharFormat);

    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Earth MOID:"), m_ItemNameCharFormat);
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(1, 3).firstCursorPosition().insertText(moidVal, m_ItemValueCharFormat);

    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Orbit class:"), m_ItemNameCharFormat);
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(2, 3).firstCursorPosition().insertText(orbitClassVal, m_ItemValueCharFormat);

    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Albedo:"), m_ItemNameCharFormat);
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(3, 3).firstCursorPosition().insertText(albedoVal, m_ItemValueCharFormat);

    table->cellAt(4, 2).firstCursorPosition().insertText(i18n("Dimensions:"), m_ItemNameCharFormat);
    table->cellAt(4, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(4, 3).firstCursorPosition().insertText(dimVal, m_ItemValueCharFormat);

    table->cellAt(5, 2).firstCursorPosition().insertText(i18n("Period:"), m_ItemNameCharFormat);
    table->cellAt(5, 2).firstCursorPosition().setBlockFormat(centered);
    table->cellAt(5, 3).firstCursorPosition().insertText(periodVal, m_ItemValueCharFormat);
}