Exemple #1
0
void Highlighter::setCSS() {
    // Keywords
    {
        KeywordPatterns.clear();

        // Load the file that contains all the keywords of this language
        QFile File(":/resources/syntax/keywords/css");
        File.open(QIODevice::ReadOnly);
        QTextStream TextStream(&File);

        // Read each line of the file and append it to the KeywordPatterns list
        while (!TextStream.atEnd()) {
            QString Line = "\\b";
            Line.append(TextStream.readLine());
            Line.append("\\b");
            KeywordPatterns.append(Line);
        }

        File.close();
    }

    // Comments
    CommentEndExpressionString = "\\*/";
    CommentStartExpressionString = "/\\*";
    SingleLineComment = "\\";

    // There are no functions in CSS
    FunctionsString = "\\";
}
Exemple #2
0
QStringList FileAction::FileRead(QString FilePath) {
    QFile File(FilePath);
    QString Text;
    QString FileText;
    QStringList FileTextinList;
    U32 FileSize = 0;

    FileTextinList.clear();

    if(!File.open(QFile::ReadOnly | QFile::Text))
    {
        qDebug() << "Could not open file";
        return FileTextinList;
    }
    FileSize = File.size();
    QTextStream TextStream(&File);

    do {
        Text = TextStream.readLine();
        emit FileReading(QString::number(((FileText.size()*100)/FileSize)) + "%",STATUSBAR_SHOW_TIME);
        FileText.append(Text+"\n\r");
    } while(!Text.isNull());

    FileTextinList = FileText.split("\n\r");
    emit FileReading("Loading Complete",STATUSBAR_SHOW_TIME);

    File.close();
    return FileTextinList;
}
void DomParser::save()
{
    //Debug
    std::cout << "Dom File:" << std::endl;
    QString xml = doc.toString();
    std::cout << xml.toUtf8().constData() << std::endl;

    QFile File("./test.xml");
       if ( File.open(QIODevice::WriteOnly) )
       {
          QTextStream TextStream(&File);
          TextStream << doc.toString() ;
          File.close();
       }
       else
          qWarning("danger :(");
}
void SvgView::loadPlan(vlePlan *plan)
{
    qWarning() << "SvgView::loadPlan";

    if ( mTplHeader.isNull() )
    {
        // ToDo : improve error handling
        qWarning() << "SvgView::loadPlan() Template error";
        return;
    }

    // Compute the height of a group
    if (mTplHeader.hasAttribute("height"))
        mGroupHeight = mTplHeader.attribute("height").toDouble();
    else
        mGroupHeight = 100;

    // Compute size of the whole plan
    int planHeight = mGroupHeight * (1 + plan->countGroups());
    int planWidth  = (mMaxWidth * mZoomLevel);

    // Create SVG document
    QDomDocument planSVG("xml");
    // Create root element
    QDomElement e = planSVG.createElement("svg");
    e.setAttribute("width",   QString(planWidth));
    e.setAttribute("height",  QString(planHeight));
    e.setAttribute("viewBox", QString("0 0 %1 %2").arg(planWidth).arg(planHeight));
    e.setAttribute("version", "1.1");

    QDate dateStart = plan->dateStart();
    QDate dateEnd   = plan->dateEnd();
    int nbDays = dateStart.daysTo(dateEnd);

    // In the plan duration is more than 1500 days
    if (nbDays > mMaxWidth)
    {
        // Update "pixel-per-day" to avoid very large picture
        qreal widgetSize = mMaxWidth;
        mPixelPerDay = (widgetSize / nbDays);
    }

    if (plan != mPlan)
    {
    qWarning() << "Plan period is from" << dateStart.toString("dd/MM/yyyy")
            << "to" << dateEnd.toString("dd/MM/yyyy")
            << "(" << nbDays<< "days)"
            << "[" << mPixelPerDay << "pixel per day]";
    }

    // First insert the time rule
    QDomElement timeGrp = mTplHeader.cloneNode().toElement();
    updateField(timeGrp, "{{name}}", "");
    updatePos  (timeGrp, 0, 0);
    updateAttr (timeGrp, "header_background", "width", QString::number(planWidth));
    float yLen = (mPixelPerDay * 365 * mZoomLevel);
    // Show Weeks
    if (yLen > 2000)
    {
        QDate r;
        if (dateStart.daysInMonth() == 1)
            r.setDate(dateStart.year(), dateStart.month(), dateStart.day());
        else
            r.setDate(dateStart.year(), dateStart.month() + 1, 1);
        while (r < dateEnd)
        {
            QDomElement newTimeStep = mTplTime.cloneNode().toElement();
            if (yLen < 5000)
                updateField(newTimeStep, "{{name}}", r.toString("dd/MM") );
            else
                updateField(newTimeStep, "{{name}}", r.toString("dd/MM/yy") );
            updateAttr (newTimeStep, "step_block", "width", QString::number(4));

            int offset = dateStart.daysTo(r);
            int aPos = (offset * mPixelPerDay * mZoomLevel);
            updatePos(newTimeStep, aPos, 0);
            timeGrp.appendChild(newTimeStep);
            r = r.addDays(7);
        }
    }
    // Show month
    else if (yLen > 500)
    {
        QDate r;
        if (dateStart.daysInMonth() == 1)
            r.setDate(dateStart.year(), dateStart.month(), dateStart.day());
        else
            r.setDate(dateStart.year(), dateStart.month() + 1, 1);
        while (r < dateEnd)
        {
            QDomElement newTimeStep = mTplTime.cloneNode().toElement();
            if (yLen < 1000)
                updateField(newTimeStep, "{{name}}", r.toString("MMM") );
            else
                updateField(newTimeStep, "{{name}}", r.toString("MMM yy") );
            updateAttr (newTimeStep, "step_block", "width", QString::number(4));

            int offset = dateStart.daysTo(r);
            int aPos = (offset * mPixelPerDay * mZoomLevel);
            updatePos(newTimeStep, aPos, 0);
            timeGrp.appendChild(newTimeStep);
            r = r.addMonths(1);
        }
    }
    // Show Year
    else
    {
        QDate r;
        if (dateStart.dayOfYear() == 1)
            r.setDate(dateStart.year(), dateStart.month(), dateStart.day());
        else
            r.setDate(dateStart.year() + 1, 1, 1);
        while (r < dateEnd)
        {
            QDomElement newTimeStep = mTplTime.cloneNode().toElement();
            updateField(newTimeStep, "{{name}}", QString::number(r.year()) );
            updateAttr (newTimeStep, "step_block", "width", QString::number(4));

            int offset = dateStart.daysTo(r);
            int aPos = (offset * mPixelPerDay * mZoomLevel);
            updatePos(newTimeStep, aPos, 0);
            timeGrp.appendChild(newTimeStep);
            r = r.addYears(1);
        }
    }
    e.appendChild(timeGrp);

    // Insert all the known groups
    for (int i=0; i < plan->countGroups(); i++)
    {
        vlePlanGroup *planGroup = plan->getGroup(i);
        vlePlanActivity *prevActivity = 0;
        int prevLen = 0;
        int prevOffset = 0;

        // Create a new Group
        QDomElement newGrp = mTplHeader.cloneNode().toElement();
        updateField(newGrp, "{{name}}", planGroup->getName());
        updatePos  (newGrp, 0, ((i + 1) * mGroupHeight));
        updateAttr (newGrp, "header_background", "width", QString::number(planWidth));

        for (int j = 0; j < planGroup->count(); j++)
        {
            vlePlanActivity *planActivity = planGroup->getActivity(j);

            QDate actStart = planActivity->dateStart();
            QDate actEnd   = planActivity->dateEnd();

            qreal actLength = (mPixelPerDay * actStart.daysTo(actEnd) * mZoomLevel);
            if (actLength < 1)
                actLength = 1;

            QDomElement newAct = mTplTask.cloneNode().toElement();
            updateField(newAct, "{{name}}", planActivity->getName());
            updateAttr (newAct, "activity_block", "width", QString::number(actLength));

            QString cfgColor("#00edda");
            QString activityClass = planActivity->getClass();
            if ( ! activityClass.isEmpty() )
            {
                QString cfg = getConfig("color", activityClass);
                if ( ! cfg.isEmpty() )
                    cfgColor = cfg;
            }
            QString fillStyle = QString(";fill:%1").arg(cfgColor);
            updateAttr (newAct, "activity_block", "style", fillStyle, false);

            int date = dateStart.daysTo(planActivity->dateStart());
            int aPos = (date * mPixelPerDay * mZoomLevel);

            if (prevActivity)
            {
                if (prevLen > aPos)
                {
                    if (prevOffset < 40)
                        prevOffset += 15;
                    updateAttr(newAct, "activity_name", "y", QString::number(prevOffset));
                }
                else
                    prevOffset = 15;
            }

            updatePos(newAct, aPos, 0);
            newGrp.appendChild(newAct);

            prevActivity = planActivity;
            prevLen = aPos + (planActivity->getName().size() * 8);
        }

        e.appendChild(newGrp);
    }
    planSVG.appendChild( e );

    QByteArray data;
    QTextStream stream(&data);
    planSVG.save(stream, QDomNode::EncodingFromTextStream);

#ifdef PLAN_OUT
    QFile File("planOut.svg");
    File.open( QIODevice::WriteOnly );
    QTextStream TextStream(&File);
    planSVG.save(TextStream, 0);
    File.close();
    mFilename = "planOut.svg";
#else
    mFilename.clear();
#endif

    mPlan = plan;

    QXmlStreamReader xData(data);
    mSvgRenderer->load(&xData);
    refresh();
}
Exemple #5
0
bool SessionManager::saveYourSession(int index)
{
    kDebug() << "SAVING YOUR OWN SESSION...";
    
    const QString & sessionPath = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/"));
    const QString & sessionName = QL1S("ses") + QString::number(index);
    
    QFile sessionFile(sessionPath + sessionName);
    if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate))
    {
        kDebug() << "Unable to open session file" << sessionFile.fileName();
        return false;
    }
    
    RekonqWindowList wl = rApp->rekonqWindowList();
    QDomDocument document("session");
    QDomElement session = document.createElement("session");
    document.appendChild(session);

    Q_FOREACH(const QWeakPointer<RekonqWindow> &w, wl)
    {
        if (w.data()->isPrivateBrowsingMode())
            continue;
        
        QDomElement window = document.createElement("window");
        int tabInserted = 0;

        window.setAttribute("name", w.data()->objectName());
        
        TabWidget *tw = w.data()->tabWidget();
        for (signed int tabNo = 0; tabNo < tw->count(); tabNo++)
        {
            KUrl u = tw->webWindow(tabNo)->url();

            tabInserted++;
            QDomElement tab = document.createElement("tab");
            tab.setAttribute("title", tw->webWindow(tabNo)->title()); // redundant, but needed for closedSites()
            // as there's not way to read out the historyData
            tab.setAttribute("url", u.url());
            if (tw->currentIndex() == tabNo)
            {
                tab.setAttribute("currentTab", 1);
            }
            if (tw->tabBar()->tabData(tabNo).toBool()) // pinned tab info
            {
                tab.setAttribute("pinned", 1);
            }
            QByteArray history;
            QDataStream historyStream(&history, QIODevice::ReadWrite);
            historyStream << *(tw->webWindow(tabNo)->page()->history());
            QDomCDATASection historySection = document.createCDATASection(history.toBase64());

            tab.appendChild(historySection);
            window.appendChild(tab);
        }
        
        if (tabInserted > 0)
            session.appendChild(window);
    }

    QTextStream TextStream(&sessionFile);
    document.save(TextStream, 2);
    sessionFile.close();

    return true;
}
Exemple #6
0
void TextStream::Test ()
{
  //
  // ctor, GetLength()
  //
  TextStream ts1;
  assert (0 == ts1._pStorage);
  assert (0 == ts1._pData);
  assert (0 == ts1._numAllocated);
  assert (0 == ts1._cachedLen);
  assert (0 == ts1.GetLength());

  const char * str = "What's up with this?\nI just want to know.\n";
  TextStream ts2 (str);
  assert (strlen (str) == ts2._cachedLen);
  assert (strlen (str) == ts2.GetLength());
  assert (0 == strcmp (str, ts2._pData));

  //
  // copy ctor
  //
  TextStream ts3 = ts2;
  assert (strlen (str) == ts3._cachedLen);
  assert (strlen (str) == ts3.GetLength());
  assert (0 == strcmp (str, ts3._pData));
  
  //
  // Clear()
  //
  ts3.Clear ();
  assert (0 == ts3._pStorage);
  assert (0 == ts3._pData);
  assert (0 == ts3._numAllocated);
  assert (0 == ts3._cachedLen);
  assert (0 == ts3.GetLength());

  //
  // op=
  //
  ts3 = ts2;
  assert (strlen (str) == ts3._cachedLen);
  assert (strlen (str) == ts3.GetLength());
  assert (0 == strcmp (str, ts3._pData));

  //
  // Append(char)
  //
  assert (0 == ts1._pStorage);
  assert (0 == ts1._pData);
  assert (0 == ts1._numAllocated);
  assert (0 == ts1.GetLength());
  ts1.Append ('H');
  assert (ts1._pStorage);
  assert (ts1._numAllocated);
  assert (1 == ts1.GetLength());
  assert (ts1._pData);
  assert (1 == strlen (ts1._pData));
  int oldAlloc = ts1._numAllocated;
  ts1.Append ('i');
  assert (oldAlloc == ts1._numAllocated);
  assert (0 == strcmp ("Hi", ts1._pData));

  //
  // Append(TextStream)
  //
  ts2 = TextStream ("Hello, ");
  ts3 = TextStream ("there.");
  ts2.Append (ts3);
  assert (0 == strcmp ("Hello, there.", ts2._pData));

  //
  // Append(FILE*)
  //
  FILE * fp = fopen ("test.dat", "w");
  SourceInfo si;
  assert (fp);
  fprintf (fp, "This is some kinda test, ya know?\n");
  fclose (fp);
  fp = fopen ("test.dat", "r");
  assert (fp);
  ts3.Append (fp, si);
  fclose (fp);
  assert (0 == strcmp ("there.This is some kinda test, ya know?\n", ts3._pData));

  //
  // Consume()
  //
  char c;
  bool stat;
  stat = ts1.Consume (c);
  assert (stat);
  assert ('H' == c);
  assert (1 == ts1.GetLength());
  stat = ts1.Consume (c);
  assert (stat);
  assert ('i' == c);
  assert (0 == ts1.GetLength());
  stat = ts1.Consume (c);
  assert (!stat);
  assert (! c);

  //
  // Snoop(), Expect()
  //
  assert (! ts3.Snoop ("there.."));
  assert (ts3.Snoop ("there."));
  assert (ts3.Snoop ("there."));
  assert (! ts3.Expect ("there.."));
  assert (ts3.Expect ("there."));
  assert (! ts3.Expect ("there."));
  assert (ts3.Expect ("This is"));
}