Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Are text descriptions posible?
Forum Updated to NodeBB v4.3 + New Features

Are text descriptions posible?

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 5.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RaubTieR
    wrote on last edited by
    #6

    I have an idea.
    @QString StartLine = "<p style=' margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;'>"; // begin HTML line
    QString EndLine = "</p>"; // end line
    QMap<QString, QString> Replacement = loadRepls("replacements.txt"); // implement that as you wish
    QString InStr = readSource("source.c"); // again wherever you get this from
    QString OutStr; // storing HTML here

    QTextStream InTxt(InStr); // read string as stream
    while(!InTxt.atEnd())
    {
    OutStr += StartLine; // new line started in HTML
    QString line = InTxt.readLine();
    QTextStream ln(line);
    while(!ln.atEnd()) // parse the source line
    {
    QString word;
    ln>>word; // this also will read signs and everything
    if(Replacement.contains(word))
    OutStr += Replacement[word];
    else OutStr += word; // just pass if symbol is not to be replaced
    }

    OutStr += EndLine;
    }
    ui->textBrowser->append(OutStr);@

    In the code above i show the following algorithm:

    Prepare output string

    Obtain the replacement table

    Obtain the source text

    Interpret source text as stream#1

    While stream#1 is not parsed

    Add line-start HTML to output

    Take one line from stream#1

    Interpret the line as stream#2

    While stream#2 is not parsed

    Take one word from stream#2

    If the word present in replacement table add replacement to output

    Else add word itself to the output

    Add line-end HTML to the output

    Pass output string to the text browser.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mariusmssj
      wrote on last edited by
      #7

      Wow, this kinda complicates things a bit then. If you got some free time I would like to have a look at my tool and what it does, to get a better understand of what I am trying to achieve =]

      [url=http://mariusmssj.brinkster.net/release.rar]Executable .rar[/url]
      [url=http://mariusmssj.brinkster.net/release.zip]Executable .zip[/url]

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RaubTieR
        wrote on last edited by
        #8

        I tried the exe, nice app :)
        But i don't see any reason that makes imposible the use of the algorithm I provided. At first I suggest to use the OutStr buffer for storing HTML code until it is ready, and pass it to the textBrowser in the very last step. This is how you can hightlight everything and then apply replacements to already hightlighted text. I dont think that any highlighting HTML tags could conflict with keywords for GL.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mariusmssj
          wrote on last edited by
          #9

          thank you =] i am going to catch some sleep and try to implement your algorithm first thing in the morning, thank you for all of your help !

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mariusmssj
            wrote on last edited by
            #10

            RaubTieR using your great examples I created something much simpler, now I instead write the code in HTML to the text file and then read from it. And it works like a charm but I got an issue.

            To make things clear this is how I crate the code
            @void MainWindow::CreateCode()
            {
            QString p = "<p style=' margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;'>"; // begin HTML line
            QString _p = "</p>"; // end line
            QString span_template1 = "<span title=";
            QString span_template2 = ">";
            QString _span = "</span>";

            QFile ScaleFile&#40;"./code_output/scale/scale.txt"&#41;;
            ScaleFile.open(QIODevice::WriteOnly | QIODevice::Truncate&#41;;
            QTextStream Sout(&ScaleFile&#41;;
            
            Sout << p + span_template1 + "'glScale does this'" + span_template2;
            Sout << "glScalef(" << GLFrame->RenderThread.getxScal();
            Sout << "f, " << GLFrame->RenderThread.getyScal();
            Sout << "f, " << GLFrame->RenderThread.getzScal() << "f);";
            Sout << _span + _p;
            ScaleFile.close();
            

            }@

            So it creates a HTML line in the the .txt file and then I read from it and it works really well, the reading code:
            @if(GLFrame->RenderThread.getScale()==1)
            {
            QFile Scfile("./code_output/scale/scale.txt");
            Scfile.open(QIODevice::ReadOnly);
            QTextStream Scstream(&Scfile);
            QString scale = Scstream.readAll();
            Scfile.close();
            if(scaleChanged) //if the text file has been updated
            {
            ui->textBrowser->setTextBackgroundColor(Qt::green);
            ui->textBrowser->append(scale);
            ui->textBrowser->setTextBackgroundColor(Qt::white);
            scaleChanged = false;
            }
            else
            {
            ui->textBrowser->append(scale);
            }
            }@

            This means that the code:
            @ if(scaleChanged) //if the text file has been updated
            {
            ui->textBrowser->setTextBackgroundColor(Qt::green);
            ui->textBrowser->append(scale);
            ui->textBrowser->setTextBackgroundColor(Qt::white);
            scaleChanged = false;
            }@

            Doesn't work any more how would I highlight the line???

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RaubTieR
              wrote on last edited by
              #11

              By the way, why dont you use the arg() method of QString here:
              @Sout << p + span_template1 + "'glScale does this'" + span_template2;@

              Also this syntax may actually be used for more sophisticated approach. For example now you generate the scale.txt file based on current parameters set by user, then you actually read it, highlight and display. But you could have persistent file as a template: you never generate it, you only have to read it and add your parameters where required.
              ... oh god... why this forum behaves so wierd with symbols that are required in code. I spent lots of time trying to post the code here, but when it came to % symbols, it began to show me things D:
              Any way here is the simplest project where you can see my implementation "LINK":http://ngageclan.ucoz.ru/test002.rar - I've put it on site where I am admin :)
              The code is very simple, but remember to copy "scale.txt" file to your EXE directory, right next to compiled app, because it searches for file there.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mariusmssj
                wrote on last edited by
                #12

                Wow I mean just wow that code worked LIKE A DREAM!!!!!!!!!

                This way I could shorten my code by at least 300 lines. Where did you acquire this kind of knowledge(as in i would love to read books/tutorials to learn more)?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  RaubTieR
                  wrote on last edited by
                  #13

                  My sources are google and this site's doc section :D and ofcourse my experience. I started Qt (not C++) less than year ago and I was amazed by it. Helping you I discovered few things for myself, since I could only theoretize about such manipulations with QTextBrowser object. Any way i have a good understanding of C++ and OOP, and HTML a bit, which helps.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mariusmssj
                    wrote on last edited by
                    #14

                    Really appreciate your help =] and i envy your knowledge.
                    Also last question if yo don't mind. My other txt files I am still loading in the old way because they are static and never change, but since they have multiple lines of code
                    "i get this weird spacing issue:":http://i.imgur.com/95Qt9.png

                    a bit of the code to show how old and new a laid out:
                    @ if(GLFrame->RenderThread.getColor()==1)
                    {
                    QFile ColourFile(QApplication::applicationDirPath()+"/code_output/colour/colour.txt");
                    ColourFile.open(QIODevice::ReadOnly);
                    QString txt = ColourFile.readAll();
                    ColourFile.close();

                        QString OutTxt;
                        QString COLOUR = "FFFFFF";
                    
                        if(colourChanged) COLOUR = "00FF00";
                    
                        OutTxt = txt.arg(COLOUR)
                                    .arg(GLFrame->RenderThread.getrCol())
                                    .arg(GLFrame->RenderThread.getgCol())
                                    .arg(GLFrame->RenderThread.getbCol());
                    
                        ui->textBrowser->append(OutTxt);
                        colourChanged = false;
                    }
                    
                    
                    QString shapePath(QString("./code_output/shape/shape_") + shapeL + ".txt");
                    
                    QFile Sfile&#40;shapePath&#41;;
                    Sfile.open(QIODevice::ReadOnly);
                    QTextStream stream(&Sfile);
                    QString shape = stream.readAll();
                    Sfile.close();
                    if(shapeChanged)
                    {
                        ui->textBrowser->setTextBackgroundColor(Qt::green);
                        ui->textBrowser->append(shape);
                        ui->textBrowser->setTextBackgroundColor(Qt::white);
                        shapeChanged = false;
                    }
                    else
                    {
                        ui->textBrowser->append(shape);
                    }@
                    
                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      RaubTieR
                      wrote on last edited by
                      #15

                      The spacing issue comes from HTML <p> margin style, which if not set, is defaulted to some value. However, I advice you to make all your texts as HTML templates, since they are static, they will only have color template for highlighting. I took my scale.txt file and duplicated it's text twice - no spacing issue with the same executable.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved